johnson1
asked on
Events that are not between dates
Hello,
I have a table with events and each event has a date.
I want to select all events that do not collide with periods of another table.
For example:
Events table: EventId int, MyDate date,
Execption table: PeriodId int, StartDate date, EndDate date
EventTable
EventId=1, MyDate='2015-01-03'
EventId=2, MyDate='2015-01-25'
ExceptionTable
PeriodId=1, StartDate='2015-01-02', EndDate='2015-01-08'
The result would be EventId=2, MyDate='2015-01-25'
The reason why eventId=1 is not selected is because it is between startdate and enddate of the exception table.
What is the most efficent way to write a query for this?
I have a table with events and each event has a date.
I want to select all events that do not collide with periods of another table.
For example:
Events table: EventId int, MyDate date,
Execption table: PeriodId int, StartDate date, EndDate date
EventTable
EventId=1, MyDate='2015-01-03'
EventId=2, MyDate='2015-01-25'
ExceptionTable
PeriodId=1, StartDate='2015-01-02', EndDate='2015-01-08'
The result would be EventId=2, MyDate='2015-01-25'
The reason why eventId=1 is not selected is because it is between startdate and enddate of the exception table.
What is the most efficent way to write a query for this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER