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 2000 Forums
 SQL Server Development (2000)
 Ignoring records with NULL values in SELECT

Author  Topic 

du-it
Starting Member

3 Posts

Posted - 2004-08-18 : 04:46:17
I want to select only those records/rows of a table which have a NULL value in a particular column (in this case the column has a datetime format).

So, how can I achieve to get only hte rows having a NULL value in column_x? I don't want to get the rows having a concrete date in column_x.

Thank you.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-18 : 04:52:21
select *
from MyTable
where col1 is null


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

du-it
Starting Member

3 Posts

Posted - 2004-08-18 : 04:55:30
Oh, of course. So easy but so difficult.
I ever tried the ISNULL function and ...where col <> null.
Thank you. It works well.

Regards,

Dirk
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-08-18 : 05:00:32
I wouldn't blame you. The ISNULL function is badly named, all it does it replace the value in the first parameter with the second if the first one is null. And col <> NULL doesn't work because NULL is not a value, it is the absence of a value. It is unknown, missing or simply not there. That is why nothing is ever equal to null, not even null itself. the only way you can actually test for nulls is to use the expression as mentioned above : WHERE col IS NULL or WHERE col IS NOT NULL as required.

P.S. there is a setting SET ANSI_NULL ON|OFF that actually lets you use = NULL or <> NULL syntax instead, but that is not recommended.

OS
Go to Top of Page
   

- Advertisement -