문제

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)
도움이 되었습니까?

해결책

Try this

Select
      BLAH
    FROM
      BLAH
    WHERE
      ...
      AND (@variable <> 'false' OR warningcode1 NOT IN (101,102,103))

다른 팁

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) )
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top