SQLTeam.com | Weblogs | Forums

IF statement under WHERE

Hello

Is it possible to specify an IF statement for a criterion?

I.e.:

select * from Table1 
where (if [a]=1 then filter by [b]=2 else filter by [c]=3)

Thanks!

Where (a=1 and b=2) or (c=3)
1 Like

Where (a=1 and b=2) or (a <> 1 and c=3)

Ori, if a could be NULL, then you need:

Where (a=1 and b=2) or ((a is null or a <> 1) and c=3)

2 Likes