I am trying to account for several situations with start and end date ranges. I am storing time values with my dates and I need to return anything that Started on or before a certain date and ended on or after or not ended at allHere is some sample code. I think I could write this a better wayDECLARE @datetime datetimeSELECT @datetime = '2007-08-28 09:28:42.803'DECLARE @temp TABLE( StartDate datetime ,EndDate datetime ,ShouldBeReturned bit)INSERT INTO @temp ( StartDate, EndDate, ShouldBeReturned )SELECT DATEADD(d,-3,@datetime), DATEADD(d,1,@datetime),1 UNION ALL --should returnSELECT DATEADD(d,-3,@datetime), NULL,1 UNION ALL --should returnSELECT DATEADD(d,-2,@datetime), DATEADD(d,-1,@datetime),0 UNION ALL --NOTSELECT DATEADD(d,-1,@datetime), DATEADD(hh,-5,@datetime),1 UNION ALL --SHOULDSELECT @datetime , DATEADD(d,1,@datetime),1UNION ALL -- SHOULDSELECT @datetime , NULL,1 UNION ALL --SHOULDSELECT DATEADD(d,1,@datetime), NULL,0 -- SHOULD notSELECT * FROM @TEMPSET @datetime = DATEADD(d,DATEDIFF(d,0,@datetime),0)SELECT * , DATEADD(ms,86399997,@DATETIME)FROM @temp WHERE (DATEADD(ms,86399997,@DATETIME) BETWEEN StartDate AND EndDate ) OR (StartDate <= DATEADD(ms,86399997,@DATETIME) AND EndDate IS NULL) OR (DATEADD(d, DATEDIFF(d, 0, @DATETIME), 0) BETWEEN StartDate AND EndDate )