Pregunta

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)
¿Fue útil?

Solución

Try this

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

Otros consejos

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) )
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top