[RESOLVED] Compare Dates in SQL, one date is NULL
hello, I need to return results depending on a condition which a date field is greater (newer) than other date field. using this for example:
select * from mytable where mydate1>olddate2;
the problem is that all results are returned because olddate2 rows are all NULL because its constructed to accept null, and no date entered yet in that field. what is the solution?
Thank's
Re: Compare Dates in SQL, one date is NULL
I want to count mydate1 as greater (newer) when other field mydate2 either has NULL value or a date that actually older than date stored in mydate1
Re: Compare Dates in SQL, one date is NULL
First I am assuming that this is MS SQL - you didn't tell us that fact and it's kind of important to the syntax we suggest.
Why wouldn't this work?
Code:
select * from mytable
where mydate1>olddate2
or olddate2 is null;
Although I must say your description of the problem is a little confusing...
Re: Compare Dates in SQL, one date is NULL
OMG! I forget that simple solution! Thank you very much for your help. SOLVED!