|
-
Feb 12th, 2012, 09:07 AM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 12th, 2012, 09:08 AM
#2
Thread Starter
Hyperactive Member
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
-
Feb 12th, 2012, 10:03 AM
#3
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...
-
Feb 12th, 2012, 10:46 AM
#4
Thread Starter
Hyperactive Member
Re: Compare Dates in SQL, one date is NULL
OMG! I forget that simple solution! Thank you very much for your help. SOLVED!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|