Sql Server Where Case Then Is Null Else Is Not Null

Posted by Fabio Montezuma on Stack Overflow See other posts from Stack Overflow or by Fabio Montezuma
Published on 2010-12-21T14:30:16Z Indexed on 2010/12/21 14:54 UTC
Read the original article Hit count: 243

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server