SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


select query for overlap date range!!!


select query for overlap date range!!!

Author
Message
sqlnewby
sqlnewby
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 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.

Sridhar-137443
Sridhar-137443
Mr or Mrs. 500
Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)

Group: General Forum Members
Points: 554 Visits: 203

Hi

Can you explain clearly the meaning of overlapped date range?

Thanks,

Sridhar!!


john-132685
john-132685
Mr or Mrs. 500
Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)

Group: General Forum Members
Points: 526 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


sqlnewby
sqlnewby
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 1

sridhar and john thanks for your response..

this has solved my problem..


Patrick Callahan
Patrick Callahan
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search