According to BOL, "Length of a string containing SQL statements (batch size) 65,536 * Network packet size". The default Network packet size=4K so limit would be 256MB.
Are you using UNION or UNION ALL? Ifv the first, try to change it to the second.
>
>I'm executing a huge SQL string from c# and i seem to be hitting some sort of limit, the SQL consists of 1000's of UNION selects and I get the following error:
>
>
Internal Query Processor Error: The query processor ran out of stack space during query optimization>
>Is there a limit to the size of the SQL you can execute?
>
--sb--