Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

select query for overlap date range!!! Expand / Collapse
Author
Message
Posted Monday, October 11, 2004 8:41 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, November 14, 2006 8:08 AM
Points: 35, Visits: 1
Hi
can any one please help me in giving the solution with an sql statement which returns the overlapping date ranges

here is the data in my table

bookingid    start                 finish
1001         2004/10/11 08:00      2004/10/11 17:30
1002         2004/10/11 09:00      2004/10/11 14:30
1003         2004/10/11 10:00      2004/10/11 18:00
1004         2004/10/11 11:00      2004/10/11 12:30
1005         2004/10/11 18:00      2004/10/11 19:30

i only wanted to return
1001
1002
1003
1004

thanks for any help

mrpro.
Post #141079
Posted Monday, October 11, 2004 10:34 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, June 5, 2014 7:52 AM
Points: 454, Visits: 194

Hi

Can you explain clearly the meaning of overlapped date range?

Thanks,

Sridhar!!

Post #141108
Posted Monday, October 11, 2004 12:31 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 29, 2006 4:30 PM
Points: 354, Visits: 1

select distinct a.keycolumn

from tablex a

       join tablex b ON a.startdate between b.startdate and b.enddate

                         OR a.enddate between b.startdate and b.enddate

 

Post #141138
Posted Tuesday, October 12, 2004 2:50 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, November 14, 2006 8:08 AM
Points: 35, Visits: 1

sridhar and john thanks for your response..

this has solved my problem..

Post #141221
Posted Tuesday, November 27, 2012 8:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 9, 2013 11:00 AM
Points: 1, Visits: 10

select distinct a.keycolumn

from tablex a

join tablex b ON a.startdate between b.startdate and b.enddate

OR a.enddate between b.startdate and b.enddate


would only return cases where the range a.startdate to a.enddate starts or ends between b.startdate and b.enddate.

if the a range starts before and ends after, what happens?

or (a.enddate > b.enddate and a.startdate < b.enddate)
should take care of it.
Post #1389244
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse