How to Short-Circuit SQL Where Clause

前端 未结 5 1633
自闭症患者
自闭症患者 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:37

    It can be "simulated" with a CASE statement. But you have to make the first condition giving a TRUE value to avoid checking of the 2nd condition :

    declare @queryWord as nvarchar(20) = 'asdas'
    
    SELECT  * 
    FROM TABLE_1
    WHERE (CASE 
           WHEN ISDATE(@queryWord) = 0 THEN 0 
           WHEN TABLE_1.INIT_DATE = CONVERT(Date, @queryWord) THEN 1
           ELSE 0 END) = 1
    

提交回复
热议问题