Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
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  

Ciupaz
Posting Yak Master

Italy
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.


Luigi

stepson
Aged Yak Warrior

Romania
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

Ciupaz
Posting Yak Master

Italy
232 Posts

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

Luigi
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.08 seconds. Powered By: Snitz Forums 2000