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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-22 : 09:12:32
|
| DrMaltz writes "Recently, I've been struggling with trying to compare 2 datetime values. The problem: There are times when one of the datetime variables is null so that causes the comparison to fail.. I even tried to add the IsNull function to my select statement to replace the value with a default if the datetime returned null, but this has not worked. Am I doing something incorrectly.. In the sample code, the comparison will fail because TestTbl has does not return any records. It still fails even if I add the IsNULL to the select statement. Here's a sample of my code..CREATE TABLE TestTbl( ActualTime datetime NULL)goCREATE TABLE TestTbl2( ActualTime datetime NULL)goINSERT TestTbl2 VALUES ('03/19/2002 9:40:00')Declare @t1 datetimeDeclare @t2 datetimeSelect @t1 = Max(isNull(ActualTime,'03/19/2002 00:00:00')) from TestTblSelect @t2 = Max(ActualTime) from TestTbl2if @t1 > @t2 Print "t1 is greater"else if @t2 > @t1 Print "t2 is greater"any thoughts would be appreciated.. Thanks in advance." |
|
|
Jay99
468 Posts |
Posted - 2002-03-22 : 09:42:37
|
INSERT Testtbl VALUES (NULL) There is a difference between haveing nothing in the table and have a row with a value of NULL . . . . that is to say, if you table has a rowcount of 0, selecting max(whatever) will always return nothing . . .Jay<O> |
 |
|
|
|
|
|