Skip to content
Advertisement

How to use SQL IN operator with CASE in select query where clause

I have the above sample T-SQL code and in the IN operator of the where clause I want to use multiple values like IN (1,2,3,4) but also I want to use the CASE operator such that I can pass different values to the IN operator depending on the value of @AreaType parameter, how can I modify the code above to achieve that?

Advertisement

Answer

You don’t use a CASE expression for that (precisely because its an expression not a statement), you use regular AND/OR logic e.g.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement