T-SQL – How to Use OR Operator in CASE THEN Statement

caset-sql

I have a situation like this

select col1, col2
from table1
where col1 = case when (booleanexp1) then a OR col1 = b 
                  when (booleanexp1) then c OR col1 = d end

I mean I need to get where col1 = a or col1 = b when booleanexp1 is TRUE,
but I get a syntax error? How is the right way to perform something like this?

Best Answer

Assuming two booleanexp1s is a misprint:

select col1, col2
from table1
where ((booleanexp1) AND (col1 IN (a, b)))
   or ((booleanexp2) AND (col1 IN (c, d)))

PS. not (booleanexp1) is one possible option of (booleanexp2)...

Related Question