How to Short-Circuit SQL Where Clause

前端 未结 5 1634
自闭症患者
自闭症患者 2020-12-10 16:17

I am trying to perform the following query in SQL server:

declare @queryWord as nvarchar(20) = \'asdas\'

SELECT  * FROM TABLE_1 
WHERE (ISDATE(@queryWord) =         


        
5条回答
  •  死守一世寂寞
    2020-12-10 16:46

    There is no defined evaluation order in a SQL statement -- except in the case of case expressions, and even there the order isn't so much defined as the result guaranteed. The conditions in your where clause could theoretically be done in parallel or alternating order.

    Case expressions differ not by having a defined order, but by having a guaranteed result. IOW, case when 1=1 then 0 When longrunningfunction() = 1 then 2 end is guaranteed to return zero, but there is no promise not to run the longrunningfunction.

提交回复
热议问题