I have tried solving this problem for a while now. I have searched a lot but no ones seems to have a similar problem.
Here is what I got:
Table 1 / Schedule
EmployeeID, PStart, PEnd
1, 2016-07-01 08:00:00, 2016-07-01 12:00:00
1, 2016-07-01 13:00:00, 2016-07-01 17:00:00
Table 2 / Bookings
EmployeeID, PStart, PEnd
1, 2016-07-01 08:00:00, 2016-07-01 08:40:00
1, 2016-07-01 09:00:00, 2016-07-01 10:10:00
1, 2016-07-01 10:30:00, 2016-07-01 11:00:00
1, 2016-07-01 13:00:00, 2016-07-01 15:00:00
1, 2016-07-01 15:00:00, 2016-07-01 15:30:00
I want to compare this two tables and get the gaps between schedule and booked time. The time that was not booked.
In this example that would be
Result table / Not booked
EmployeeID, PStart, PEnd
1, 2016-07-01 08:40:00, 2016-07-01 09:00:00
1, 2016-07-01 10:10:00, 2016-07-01 10:30:00
1, 2016-07-01 11:00:00, 2016-07-01 12:00:00
1, 2016-07-01 15:30:00, 2016-07-01 17:00:00
The speed of the query is very important. The employee count is above 150, so there is a lot of rows. The date range of which we are going to use might be limited (get gaps for two weeks for instance) instead of showing all gaps since the beginning of time. But only if that helps the query speed.
Thanks in advance.
Regards, Adam