Odd SQL Results
Posted
by
Ryan Burnham
on Stack Overflow
See other posts from Stack Overflow
or by Ryan Burnham
Published on 2012-10-18T22:48:00Z
Indexed on
2012/10/18
23:00 UTC
Read the original article
Hit count: 580
So i have the following query
Select id, [First], [Last] , [Business] as contactbusiness, (Case When ([Business] != '' or [Business] is not null)
Then [Business] Else 'No Phone Number' END) from contacts
The results look like
id First Last contactbusiness (No column name)
2 John Smith
3 Sarah Jane 0411 111 222 0411 111 222
6 John Smith 0411 111 111 0411 111 111
8 NULL No Phone Number
11 Ryan B 08 9999 9999 08 9999 9999
14 David F NULL No Phone Number
I'd expect record 2 to also show No Phone Number
If i change the "[Business] is not null" to [Business] != null then i get the correct results
id First Last contactbusiness (No column name)
2 John Smith No Phone Number
3 Sarah Jane 0411 111 222 0411 111 222
6 John Smith 0411 111 111 0411 111 111
8 NULL No Phone Number
11 Ryan B 08 9999 9999 08 9999 9999
14 David F NULL No Phone Number
Normally you need to use is not null rather than != null. whats going on here?
© Stack Overflow or respective owner