Thursday, March 22, 2012

case null

how do you deal with case null?
CASE @.test WHEN NULL THEN .........[columnname] =
CASE
WHEN [columnname] IS NULL THEN 'It's NULL'
ELSE 'It's not NULL'
END|||The expression implies:
CASE WHEN @.test = NULL THEN...
And you probably know value = NULL evaluates to UNKNOWN which in turn (in mo
st cases) evaluates to
FALSE. Here's how to do:
CASE WHEN @.test IS NULL THEN...
So, use a searched case instead of a simple case.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Justin" <jus820@.hotmail.com> wrote in message news:%23EpRzureGHA.4828@.TK2MSFTNGP05.phx.gbl
..
> how do you deal with case null?
> CASE @.test WHEN NULL THEN .........
>|||CASE
WHEN @.test IS NULL THEN...
HTH
Vern
"Justin" wrote:

> how do you deal with case null?
> CASE @.test WHEN NULL THEN .........
>
>|||for future reference...
null is not a value. and it's a grave mistake to use it as such in the
database. try to avoid inserting null in the database at all cost;
certain cases are unavoidable, however.
since it's not a value, you can't compare against it. ie. x = null.sql

No comments:

Post a Comment