I have a large SQL query with multiple statements and
UNION ALL. I am doing something like this now:
DECLARE @condition BIT; SET @condition = 0; SELECT * FROM table1 WHERE @condition = 1; UNION ALL SELECT * FROM table2
In this case, table1 won't return any results. However, that query is complex with many joins (such as
FullTextTable). The execution plan's estimate shows a high cost, but the actual number of rows and time to execute seems to show otherwise. Is this the most efficient way of filtering a whole query, or is there a better way? I don't want anything in the first select to run, if possible.