Comparing Date Range columns with Date Range Parameters always confuse us.
Here is the simple solution using below query:
Declare @DateFrom DateTime, @DateTo DateTime
Set @DateFrom = '2012/10/01'
Set @DateTo = '2012/10/30'
Select *
From Schedule
Where
ScheduleFrom < = @DateTo And
ScheduleTo >= @DateFrom
This is also described as Allen's Interval Algebra.
http://en.wikipedia.org/wiki/Allen%27s_Interval_Algebra
Randhir
Here is the simple solution using below query:
Declare @DateFrom DateTime, @DateTo DateTime
Set @DateFrom = '2012/10/01'
Set @DateTo = '2012/10/30'
Select *
From Schedule
Where
ScheduleFrom < = @DateTo And
ScheduleTo >= @DateFrom
This is also described as Allen's Interval Algebra.
http://en.wikipedia.org/wiki/Allen%27s_Interval_Algebra
Randhir
No comments:
Post a Comment