我正在尝试在 where 中使用 Not In 和布尔变量来确定是否在集合中搜索某些东西。例如:
Select
BLAH
FROM
BLAH
WHERE
...
AND CASE WHEN @variable = 'false' THEN
warningcode1 NOT IN (101,102,103)
试试这个
Select
BLAH
FROM
BLAH
WHERE
...
AND (@variable <> 'false' OR warningcode1 NOT IN (101,102,103))
只需使用:
AND (@variable <> 'false' OR warningcode1 NOT IN (101,102,103))
因此,警告代码1 仅在变量 = 'false' 时才重要,否则将被忽略。
试试这个
AND IF( @variable = 'false' , warningcode1 NOT IN (101,102,103) , warningcode1 IN (101,102,103) )