Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Overlapping range dates
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

232 Posts

Posted - 10/08/2012 :  03:51:06  Show Profile  Reply with Quote
Hello all,
I have a table (SQL Server 2008 R2) with 2 datetime fields, like:

StartDate - EndDate

Now I have a query with 2 variables, Date1 and Date2.

How can I know if there is an overlapping between these dates?

For example I have to check if the range between Date1 and Date2
is inside (also for one second) between StartDate and EndDate in the table.

How can I accomplish this?

Thank you.


Aged Yak Warrior

545 Posts

Posted - 10/08/2012 :  04:48:55  Show Profile  Reply with Quote
where @data1>StartDate
and @data1<EndDate
and @data2>StartDate
and @data2<EndDate

Edited by - stepson on 10/08/2012 04:49:29
Go to Top of Page

Posting Yak Master

232 Posts

Posted - 10/08/2012 :  10:02:04  Show Profile  Reply with Quote
Thanks very much Stepson.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000