Sql Server Where Case Then Is Null Else Is Not Null
- by Fabio Montezuma
I have a procedure which receive a bit variable called @FL_FINALIZADA.
If it is null or false I want to restrict my select to show only the rows that contain null DT_FINALIZACAO values. Otherwise I want to show the rows containing not null DT_FINALIZACAO values.
Something like this:
SELECT * FROM ... WHERE
...
AND (OPE.DT_FINALIZACAO = CASE WHEN (@FL_FINALIZADA <> 1) THEN NULL END OR OPE.DT_FINALIZACAO IS NOT NULL)
In this case I receive the message:
None of the result expressions in a
CASE specification can be NULL.
How can I achieve this?
Thanks in advance.