Groups | Blog | Home
all groups > sql server (microsoft) > april 2007 >

sql server (microsoft) : Comparing two dates with null values


Manikandan
4/25/2007 5:37:42 AM
Hi,
I have a doubt of querying a date column
Table Name:Detail
Name(varchar) sdate(datetime,null) ddate(datetime,null)
Value(int)
ss 2007-04-03 10:41:12.410 NULL
10
rr 2007-04-03 10:41:12.410 2004-04-03 10:41:12.410 10
tt 2007-04-03 10:41:12.410 2005-04-03 10:41:12.410 10

I need to query the records where sdate > ddate
The query i used is
Select * from detail where sdate>ddate.
The above query returns two rows only

rr 2007-04-03 10:41:12.410 2004-04-03
10:41:12.410 10
tt 2007-04-03 10:41:12.410 2005-04-03
10:41:12.410 10

I think the query is wrong because it has to give three rows because
2007-04-03 10:41:12.410> null.
Is it right?
How to write the above query to compare the null values with date
I need all the three rows(i.e sdate > ddate(ddate may be null, at that
case it has to give sdate)

Thanks & Regards,

Manikandan
Ed Murphy
4/25/2007 9:21:54 AM
[quoted text, click to view]

No. "Null" generally means "unknown", so "2007-04-03 > null" is
unknown i.e. not true.

[quoted text, click to view]

WHERE SDATE > DDATE OR DDATE IS NULL

or

AddThis Social Bookmark Button