Try this
Select
BLAH
FROM
BLAH
WHERE
...
AND (@variable <> 'false' OR warningcode1 NOT IN (101,102,103))
Question
I'm trying to use Not In with a boolean variable in the where to determine whether or not to search in a set for something. For example:
Select
BLAH
FROM
BLAH
WHERE
...
AND CASE WHEN @variable = 'false' THEN
warningcode1 NOT IN (101,102,103)
Solution
Try this
Select
BLAH
FROM
BLAH
WHERE
...
AND (@variable <> 'false' OR warningcode1 NOT IN (101,102,103))
OTHER TIPS
Just use:
AND (@variable <> 'false' OR warningcode1 NOT IN (101,102,103))
So the warningcode1 matters only if the variable = 'false', othwerwise it will be ignored.
try this with if
AND IF( @variable = 'false' , warningcode1 NOT IN (101,102,103) , warningcode1 IN (101,102,103) )