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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Overlapping range dates

Author  Topic 

Ciupaz
Posting Yak Master

232 Posts

Posted - 2012-10-08 : 03:51:06
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

545 Posts

Posted - 2012-10-08 : 04:48:55
where @data1>StartDate
and @data1<EndDate
and @data2>StartDate
and @data2<EndDate
Go to Top of Page

Ciupaz
Posting Yak Master

232 Posts

Posted - 2012-10-08 : 10:02:04
Thanks very much Stepson.

Luigi
Go to Top of Page
   

- Advertisement -