The following are table data:
CREATE TABLE
Now the goal is to get period_no, which has 2 given dates that will be compared with periods period_from and period_to.
Example1: date1 = '2010-11-01 00:00:00' date2 = '2011-10-31 00:00:00'
This will return 7 as period_no
Example2: date1 = '2005-11-01 00:00:00' date2 = '2007-10-31 00:00:00'
It should not return period_no, since the specified date range is not in the range period_from and period_to in the column in the row. Overlap dates are not allowed.
The rule is to get period_no if the 2 given date has a match or is in the range period_from and period_to a column in a row.
How to make this query in T-SQL?
Thanks in advance!
source share