SQL Server Forums
Profile | Register | 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)
 Datetime interval "inside" another datetime inter.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ciupaz
Posting Yak Master

Italy
227 Posts

Posted - 12/05/2012 :  09:07:38  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/05/2012 :  09:23:31  Show Profile  Reply with Quote
WHERE
	PlantStartDate < @RefEndDate
	AND PlantEndDate > @RefStartDate
Go to Top of Page

Ciupaz
Posting Yak Master

Italy
227 Posts

Posted - 12/05/2012 :  09:48:31  Show Profile  Reply with Quote
Thank you very much again Sunitabeck :-)

Luigi
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/05/2012 :  10:00:13  Show Profile  Reply with Quote
My pleasure :-)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000