I was wondering if there's a limit on a number of UNION'ed SELECT statements I can send to an SQL Server? I may have up to 36 done in one SQL statement, so it becomes quite long, character wise. (Also each of those SELECT statements is a somewhat complex by itself with CASE WHEN statements in it.)
You probably confused “union all” with “cross join”. There are no general limits on SQL statement length, but there can be restrictions in the specific DBMS.
Conclusion. Combining several tables to one large table is possible in all 3 ways. As we have seen, the behavior of UNION in SQL Server and UNION in DAX within Power BI is very similar.
Save this question. Show activity on this post. While each of both select statements takes less than 1 second when executed separately.
TIP: SELECT LIMIT is not supported in all SQL databases. For databases such as SQL Server or MSAccess, use the SELECT TOP statement to limit your results. The SELECT TOP statement is Microsoft's proprietary equivalent to the SELECT LIMIT statement.
From SQL 2008 BOL
"Any number of UNION operators can appear in a Transact-SQL statement"
Also from MSDN "Maximum Capacity Specifications for SQL Server" (2008):
Batch size (1) 65,536 * Network Packet Size
Length of a string containing SQL statements (batch size) (1) 65,536 * Network packet size
(1) Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 KB, and is controlled by the network packet size configuration option.
To my mind, that means 268,435,456 bytes when using defaults. Please say your query is shorter than that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With