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)
 Datetime interval "inside" another datetime inter.

Author  Topic 

Ciupaz
Posting Yak Master

232 Posts

Posted - 2012-12-05 : 09:07:38
Hello all,
I have a table - PlantHistory - with 2 datetime fields, like:


PlantStartDate - PlantEndDate

2000-01-01 00:00:00 2099-12-31 23:59:59
2002-01-01 00:00:00 2009-12-31 23:59:59
...


Then I have stored procedure that has 2 datetime parameters, RefStartDate - RefEndDate.


Now I have to extract from PlantHistory table only the record that has at least one second
of the fields PlantStartDate and PlantEndDate
"inside" my RefStartDate and RefEndDate parameters.


How can I write this WHERE clause?


Luigi

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-05 : 09:23:31
[code]WHERE
PlantStartDate < @RefEndDate
AND PlantEndDate > @RefStartDate[/code]
Go to Top of Page

Ciupaz
Posting Yak Master

232 Posts

Posted - 2012-12-05 : 09:48:31
Thank you very much again Sunitabeck :-)

Luigi
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-05 : 10:00:13
My pleasure :-)
Go to Top of Page
   

- Advertisement -