IN inside a case statement of WHERE clause
Is it possible to add IN inside a case statement of WHERE clause as below:
WHERE
CASE WHEN @id IN(1,2) THEN ...
CASE WHEN @id IN(3,4) THEN...
I got syntax error...I then tried by removing IN adding OR as below:
开发者_C百科CASE WHEN @id = 1 OR @id = 2 THEN ...
CASE WHEN @id = 3 OR @id = 4 THEN ...
It worked....but just for curiosity I want to know whether somehow we can use IN... please help
You need to explain further. This is definitely valid syntax:
DECLARE @id int = 1
SELECT 'Foo'
WHERE 1 = CASE WHEN @id IN (1,3) THEN 1
ELSE 0
END
What is in your THEN
statement?
You might try to put the condition in parenthesis, like:
( @id IN(1,2) )
精彩评论