January 27, 2005 at 7:38 pm
What is the best way to treat a column when some of the values are NULL.
Example, I have a table that has the following records
SequenceId StartDate EndDate
----------- ------------------------------------------------------ ------------------------------------------------------
1 2000-01-01 00:00:00.000 2005-01-28 00:00:00.000
2 2000-01-01 00:00:00.000 2005-01-27 00:00:00.000
3 NULL 2005-01-27 00:00:00.000
If I perfrom the following query, it will only return the first 2 records. How do I calculate StartDate < EndDate when the StartDate could potentially be NULL?
SELECT * FROM xyz
WHERE StartDate < EndDate
January 27, 2005 at 7:49 pm
It's a bit difficult to believe that you would ever have a NULL StartDate with a valid EndDate. Normally, it's the other way around. But, no worries...
For NULL StartDates, I would treat them as if they were '01/01/1900' and I would treat NULL EndDates as if they were '12/31'9999'
SELECT * FROM xyz
WHERE ISNULL(StartDate,'01/01/1900') < ISNULL(EndDate,'12/31/9999')
Do be advised that this method may not use an index on either date...
--Jeff Moden
Change is inevitable... Change for the better is not.
January 27, 2005 at 7:59 pm
January 28, 2005 at 4:22 am
Yup... I know the feeling... you should see the one at work. Glad to help.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply