Case filter in where condition based on parameter

hello all,

I have one filter in my Storew procedure ..

@is_Delay_Files Bit,

now , my Col1 have values of two types  >0 and <0 (i.e. -1,-2 etc.)

now , what i want to achieve is when i pass 1 to parameters then all the rows which have Col1 <0 should return and when i pass

0 then all the rows which have Col1 >0 should return .. 

i have tried this but cant able to do it in one statement..

AND (CASE WHEN @Is_Delay_File=1 THEN -1 ELSE Col1 END )>=(CASE WHEN @Is_Delay_File=0 THEN 0 ELSE -100000 END)

Please, Help Urgent.. 

March 30th, 2015 2:05am

i think what you need is this

WHERE ((Col1 < 0 AND @is_Delay_Files = 1)
OR  (Col1 > 0 AND @is_Delay_Files = 0))
....

Free Windows Admin Tool Kit Click here and download it now
March 30th, 2015 2:29am

where ((col1<case when @is_delay_file =1 then 0 End) or (col1>Case when@is_Delay_file=0 then 0 end))

March 30th, 2015 2:29am

Thanks ... all..

Shan210 .. pure knowledge .. 

Free Windows Admin Tool Kit Click here and download it now
March 30th, 2015 2:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics