T-SQL 1=1 Performance Hit

前端 未结 8 764
谎友^
谎友^ 2020-12-06 04:33

For my SQL queries, I usually do the following for SELECT statements:

SELECT ...
FROM table t
WHERE 1=1
  AND t.[column1] = @param1
  AND t.[column2] = @para         


        
8条回答
  •  醉酒成梦
    2020-12-06 05:30

    No performance hit. Even if your WHERE clause is loaded with a large number of comparisons, this is tiny.

    Best case scenario is that it's a bit-for-bit comparison. Worse case is that the digits are evaluated as integers.

提交回复
热议问题