views:

54

answers:

3

Hello all,

I have a subquery, used in WHERE section:

A.column <> B.column

Unfortunately, it doesn't work, if either A.column or B.column is NULL. So, I converted it to:

((A.column <> B.column) OR ((A.column IS NULL) <> (B.column IS NULL)))

, presuming that "Table.column IS NULL" is boolean value and I can compare 2 boolean values. But...

Incorrect syntax near '<'.

I don't like

((A.column <> B.column) OR ((A.column IS NULL) AND (B.column IS NOT NULL)) OR
((A.column IS NOT NULL) AND (B.column IS NULL)))

How could I workarounf this?

Regards,

+1  A: 

Use ISNULL function.

gandjustas
A: 
(ISNULL(A.column,0)) <> (ISNULL(B.column,0))
RPM1984
Isn't that going to treat 0 and NULL identically? A row with `A=0` and `B=NULL` won't be selected.
paxdiablo
i thought that's what he intended. might be wrong
RPM1984
As paxdiablo wrote, I have to have a never-used value. Unfortunately, I have no such values. Even worse, to use ISNULL, I have to know column type. I'd better use ((NULL AND NOT NULL) OR (NOT NULL AND NULL)) instead.
noober
+2  A: 

NULLIF yields null when two values are equal =)

WHERE NULLIF(A.column, B.column) IS NOT NULL
David Hedlund
Looks good... I'll try this.
noober