[thelist] SQL query question (easy)

John Hicks johnlist at gulfbridge.net
Wed May 10 01:01:09 CDT 2006


April wrote:
> I have start_on and end_on dates, which can also be null.  I'm writing a 
> SQL select to find all instances where a date is within the start_on, 
> end_on range and but returns if one or the other is null too.  If the 
> start_on is null and the end_on is greater than the date, then it needs 
> to return.
> 
> Basically, I need to combine:
> start_on <= now() AND end_on >= now()
> with:
> start_on IS NULL AND end_on IS NULL
> start_on IS NULL AND end_on >= now()
> start_on <= now() AND end_on IS NULL

How about:

where
(start_on <= now() OR start_on IS NULL)
AND (end_on <= now() OR end_on IS NULL)

--J




More information about the thelist mailing list