in reply to SQL Query for Scheduling

This can be done fairly straight-forwardly in SQL without a really complicated query, without subselects, and without requiring oracle:

Start at the times table, join to the schedule slots where the appt time is completely within the available time. Then try (LEFT) to join to that employee's appointments where there's any kind of time intersection. Now, in the WHERE clause, only accept rows where the LEFT JOIN failed (i.e. no conflicting appointments).
SELECT t.start, t.end FROM appointment_times t JOIN scheduled_availability s ON AND t.start >= s.start AND t.end <= s.end LEFT JOIN appointments a ON a.EmployeeID = s.EmployeeID AND t.start <= a.end AND t.end >= a.start WHERE a.EmployeeID IS NULL ;

Replies are listed 'Best First'.
Re^2: SQL Query for Scheduling
by Anonymous Monk on Aug 16, 2005 at 21:13 UTC
    Thanks! The real life query is a little bit more complicated than what I described in my question, but I think this will work perfectly.