I am still can’t seem to crack this problem. In order to hopefully clarify what I am trying to do, here are some examples of what I would like to happen.
The main steps are:- Check to see is the user is qualified
- Check to see if the user has any times that they cannot work as listed in tblUserAvailability. If they are free, then list them as available for that event. A problem here seems to be that if John Doe is unavailable on 6/25/2011, since there is an entry on 6/21/2011 that is outside of the event date range, it shows him as available.
- If a qualified person has no entries in tblUserAvailability then they are automatically available and should be listed as well. This does not seem to be occurring correctly for me.
tblUserAvailability
Code:
AvailabilityID UserID LastName FirstName StartDate EndDate StartTime EndTime
11 1 Doe John 6/21/2011 6/21/2011 7:00:00 AM 9:00:00 AM
12 1 Doe John 6/25/2011 6/25/2011 10:00:00 AM 12:00:00 PM
15 1 Doe John 6/25/2011 6/25/2011 6:00:00 PM 8:00:00 PM
16 4 Smith Bill 6/25/2011 6/25/2011 12:00:00 PM 8:00:00 PM
tblUsers
Code:
UserID LastName FirstName Qual
1 Doe John Yes
4 Smith Bill Yes
5 Doe Jane Yes
6 Schmoe Joe No
Scenario 1
Event Start Date: 6/25/2011, Event Start Time: 5:00 AM
Event End Date: 6/25/2011, Event End Time: 6:00 AM
Desired Results for Scenario 1
In this case, Joe Schmoe is not included since he is not qualified, however all of the other users are qualified and do not have any other periods of unavailability.
Available Personnel
Code:
LastName FirstName
Doe John
Doe Jane
Smith Bill
Scenario 2
Event Start Date: 6/25/2011, Event Start Time: 10:00 AM
Event End Date: 6/25/2011, Event End Time: 11:00 AM
Desired Results for Scenario 2
In this case Joe Schmoe is still not included, but John Doe is removed because he has an overlap with his 10:00 AM to 12:00 PM blocked out time. This only leaves Jane Doe and Bill Smith.
Available Personnel
Code:
LastName FirstName
Doe Jane
Smith Bill
Scenario 3
Event Start Date: 6/25/2011, Event Start Time: 5:00 PM
Event End Date: 6/25/2011, Event End Time: 9:00 PM
Desired Results for Scenario 3
In this case Joe Schmoe is still not included. Now, John Doe is removed because he has an overlap with his 10:00 AM to 12:00 PM blocked out time, and Bill Smith is removed because of his 12:00 PM to 8:00 PM blocked out time. This only leaves Jane Doe as available.
Available Personnel
Code:
LastName FirstName
Doe Jane
I would like this to be done in a query if possible, I just can’t seem to figure out how to accomplish this task. Any further ideas would really be helpful.
Thanks,
Kevan