A Theory Question...
When a set of queries as given below is fired then...
Create table Temp1(C1 varchar(2))
Create table Temp2(C1 varchar(2))
insert into Temp1 Values('A'),(NULL),('B')
insert into Temp2 Values('B'),(NULL),('C'),(NULL)
select *from Temp1 A,Temp2 B
where A.C1 <> B.C1
...gives...
I used A.C1 <> B.C1
in the Where
clause.
But I expect...
To get expected result as output I needed to use ISNULL(A.C1,'') <> ISNULL(B.C1,'')
in the Where
clause.
My Question is why do I need to use ISNULL
every time for getting output as expected, as NULL
is not equal to any string data.
Quote from here is perfect:
Null is not equal to anything, therefore comparison always fails.
For example try this query:
it won't return any row!
The handle nulls you have to use
is null
oris not null
:return exactly the same values that your query with
ISNULL
returns.