The only way to guarantee the evaluation order is to use CASE.
WHERE CASE WHEN @a IS NULL THEN 1 WHEN a = @a THEN 1 ELSE 0 END = 1 AND
In my experience, this is usually slower than just letting the DB machine figure it out.
The TerrorAustralis answer is generally the best option for non-nullable columns.
source share