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)
 Not Equal Operator

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-02-16 : 22:37:24
I have nuallable column and I use <> operator in query. It can return the results if the column is not null [other value] . But it doesnt return the result if the col is null.

where col1 <> '123'


Regards,

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-16 : 22:46:33
NULL value when compare with anything it will give FALSE.

If you want to include the NULL value, check for col1 is NULL


where col1 <> '123'
or col1 is null



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-16 : 23:53:21
the reason is null is not regarded as a value itself but it just represents a state of unknown value. So unless you change default ANSI NULL setting to regard NULL also as a value all operatoes like =,<> ,> etc ignore NULL values. comparison with NULLs are done in such cases by means of IS NULL and IS NOT NULL.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -