Is it possible to use CASE with IN?

Posted by dkackman on Stack Overflow See other posts from Stack Overflow or by dkackman
Published on 2010-05-27T19:41:06Z Indexed on 2010/05/27 20:21 UTC
Read the original article Hit count: 211

Filed under:
|
|

I'm trying to construct a T-SQL statement with a WHERE clause determined by an input parameter. Something like:

SELECT * FROM table
WHERE id IN
CASE WHEN @param THEN
(1,2,4,5,8)
ELSE
(9,7,3)
END

I've tried all combination of moving the IN, CASE etc around that I can think of. Is this (or something like it) possible?

© Stack Overflow or respective owner

Related posts about tsql

Related posts about parameter