0
votes

I need query which will check user supplied date range is in between the existing table startdate and enddate. if any of the date of user supplied date range is in between the tables start date and end date,it should retrun that record from table.

for example user supply date range is from 1 may 2012 to 5 may 2012. then query must check that 1 may 2005 2 may 2005 3 may 2005 4 may 2005 5 may 2005 (all dates) is in between startdate and enddate of existing table.

please reply.

2
Although there are other ways to do it, there's a basic SQL standard built-in operator just for this: [BETWEEN] (msdn.microsoft.com/en-us/library/ms187922.aspx).Gerardo Lima

2 Answers

6
votes

Overlaps test for two intervals:

( '2012-05-01' <= enddate
AND  startdate <= '2012-05-05'
) 
1
votes
Select * from table where datecolumn between @date1 and @date2