Are boolean expressions in SQL WHERE clauses short-circuit evaluated ?
For example:
SELECT *
FROM Table t
WHERE @key IS NULL OR (@key IS NOT NULL
i don't know about short circuting, but i'd write it as an if-else statement
if (@key is null)
begin
SELECT *
FROM Table t
end
else
begin
SELECT *
FROM Table t
WHERE t.Key=@key
end
also, variables should always be on the right side of the equation. this makes it sargable.
http://en.wikipedia.org/wiki/Sargable