Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Evaluating if column is NULL

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2008-09-30 : 12:20:45
I've got a bit column in my database.

I noticed that this statement does not return rows with NULL in that column

SELECT * FROM table WHERE bitColumn <> 1

This works however

SELECT * FROM table WHERE (bitColumn <> 1 OR bitColumn IS NULL)

I was just wondering why that is the case?

Thanks

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-09-30 : 12:33:33
a null value means a value is non existant, therefore it can not compare it to anything.

Also you can use


SELECT * FROM table WHERE coalesce(bitColumn,0) <> 1



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-30 : 12:39:58
quote:
Originally posted by Vinnie881

a null value means a value is non existant, therefore it can not compare it to anything.
Also you can use


SELECT * FROM table WHERE coalesce(bitColumn,0) <> 1



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881


Which is true unless you've set ANSI NULLS property to OFF
Go to Top of Page
   

- Advertisement -