How do I do multiple CASE WHEN conditions using SQL Server 2008?

前端 未结 10 1950
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 09:57

What I\'m trying to do is use more than one CASE WHEN condition for the same column.

Here is my code for the query:

   SELECT   Url=\'\',
                    


        
10条回答
  •  醉梦人生
    2020-11-27 10:28

    Combining all conditions

    select  a.* from tbl_Company a
    
    where  a.Company_ID NOT IN (1,2)  
    
    AND (   
            (0 = 
                CASE WHEN (@Fromdate = '' or @Todate='')
                    THEN 0 
                    ELSE 1  
                END
            )      -- if 0=0 true , if 0=1 fails (filter only when the fromdate and todate is present)
                    OR
            (a.Created_Date between @Fromdate and @Todate )                 
        )
    

提交回复
热议问题