I have a database with the following tables: tblPeople, tblSpaces, and tblMMPeople_Spaces, which is attached. The tblMMPeople_Spaces table is to record assignment of people to authorized space and records the start and end dates of the assignment, if known. If not known, the start or end date may be blank, but to avoid dealing with null dates, I am assuming that no start date = 1/1/1950 and no end date = 12/31/2050.
I am trying to create a query that will tell me which spaces do not currently have a person assigned which is determined by using the start date, the end date, and the date when the query is run.
I have tried and cannot figure out how to do this. I have been able to define the set of records for when some is assigned but the opposite is more difficult, and designing the query has stumped me for a while so I thought I would ask for help.
Here is what I came up with for when a position has someone assigned: when at least one record in tblMMPeople_Spaces has a personID, the SpaceID, and the following start and end date scenarios:
No start or end date.
No start date and an end date that is in the future.
A start date in the past and no end date.
A start date in the past and an end date that is in the future.
Since a Space may have multiple people assigned both at the same time (overlap of people) and during different time periods, the definition is not easy. To avoid dealing with null dates, I am assuming that no start date = 1/1/1950 and no end date = 12/31/2050.
Case 1. Set of records in tblMMPeople_Space with no SpaceID. These shouldn't exist but, if they did, this would mean that there are records in the table with no spaces attached (orphans?).
Case 2. Set of records in tblMMPeople_Spaces with a specific SpaceID but no PersonID. If all records in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant. If some records in tblMMPeople_Spaces with the specific SpaceID are not in this record set, it means they have a SpaceID and a PersonID and are handled under 3, 4, 5, or 6 depending on the start and end dates.
Case 3. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date of today or in the past, and an end date in the past. If all records in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant.
Case 4. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date of today or in the past, and an end date of today or in the future. If any record(s) in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is not vacant.
Case 5. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date in the future, and an end date in the past. If all record(s) in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant. This one would only occur if there was a data entry error.
Case 6. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date in the future, and an end date of today or in the future. If all record(s) in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant.
I would really appreciate any help making this query.
Thanks
I am trying to create a query that will tell me which spaces do not currently have a person assigned which is determined by using the start date, the end date, and the date when the query is run.
I have tried and cannot figure out how to do this. I have been able to define the set of records for when some is assigned but the opposite is more difficult, and designing the query has stumped me for a while so I thought I would ask for help.
Here is what I came up with for when a position has someone assigned: when at least one record in tblMMPeople_Spaces has a personID, the SpaceID, and the following start and end date scenarios:
No start or end date.
No start date and an end date that is in the future.
A start date in the past and no end date.
A start date in the past and an end date that is in the future.
Since a Space may have multiple people assigned both at the same time (overlap of people) and during different time periods, the definition is not easy. To avoid dealing with null dates, I am assuming that no start date = 1/1/1950 and no end date = 12/31/2050.
Case 1. Set of records in tblMMPeople_Space with no SpaceID. These shouldn't exist but, if they did, this would mean that there are records in the table with no spaces attached (orphans?).
Case 2. Set of records in tblMMPeople_Spaces with a specific SpaceID but no PersonID. If all records in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant. If some records in tblMMPeople_Spaces with the specific SpaceID are not in this record set, it means they have a SpaceID and a PersonID and are handled under 3, 4, 5, or 6 depending on the start and end dates.
Case 3. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date of today or in the past, and an end date in the past. If all records in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant.
Case 4. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date of today or in the past, and an end date of today or in the future. If any record(s) in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is not vacant.
Case 5. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date in the future, and an end date in the past. If all record(s) in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant. This one would only occur if there was a data entry error.
Case 6. Set of records in tblMMPeople_Spaces with a specific SpaceID, any PersonID, a start date in the future, and an end date of today or in the future. If all record(s) in tblMMPeople_Spaces with the specific SpaceID are also in this record set, the Space is vacant.
I would really appreciate any help making this query.
Thanks