A comment in this question:
Do not rely on short-circuiting … Those clauses could be evaluated in any order SQL Server sees fit.
As it relates to this answer:
SELECT * FROM TABLE WHERE (@vari is null or col = @vari)
- Is this correct?
- Is there a good test setup, perhaps in SQL fiddle, that can reproduce this phenomenon? (used that term pretty loosely)
- Does this only occur in WHERE clauses? Or perhaps only with AND/OR operators?
I ask this because I haven’t found anything online that explicitly states this.
Read here
SQLFiddle
Sample setup