In SQL SERVER 2008 I'm thinking about a query such as:
SELECT ...
FROM ...
WHERE ...
AND @a=1
UNION
SELECT ...
FROM ...
WHERE ...
AND @a=2
Given that @a is clearly the same value, and therefore either the first SELECT returns results or the second SELECT does, will the query optimizer identify one of the queries as false and not run it? Would it be better for me to put them in an IF statement? The actual query is a bit more complicated than written of course, so the if would make it like 4 different queries, which would be a pain to maintain.
I'm hoping the optimizer is smart enough to see the 'and false' and not waste time with it.

WHEREcriteria in parallel to make it faster, which in your case would be slower. – JNK♦ Oct 5 '12 at 14:42