I have a many table with list of dates showing an active and inactive status of people. The table has 3 columns like this…
In the sample data above, the first person, 14589, is currently active as of 9/22/2008, and they were inactive between 10/14/2007 and 9/22/2008. The second person is currently inactive. They we inactivated on 01/22/2009. They were active between 05/02/2006 and 07/04/2007, and then again between 02/12/2008 and 01/22/2009.
What I want to be able to do is to take a list if Person Ids and find out who was active on a certain date, or even better, in a date range.
One thought was to take the data as it currently is and change it in to a table like the one below, but I was having troubles writing the queries to do it.
With this I could see if a certain date was Between [Active] And [Inactive] Or Date Is >[Active] and [Inactive] Is Null. I tried to build the table with a crosstab query (PersonID = Row, Status = Column, StatusDate = Value), but it would only give me on row for each person ID because it was looking at the Max or Min of StatusDate.
Any help is appreciated.
Greg
Code:
Person ID Status StatusDate
14589 Active 06/01/2007
14589 Inactive 10/14/2007
14589 Active 09/22/2008
78569 Active 05/02/2006
78569 Inactive 07/04/2007
78569 Active 02/12/2008
78569 Inactive 01/22/2009
What I want to be able to do is to take a list if Person Ids and find out who was active on a certain date, or even better, in a date range.
One thought was to take the data as it currently is and change it in to a table like the one below, but I was having troubles writing the queries to do it.
Code:
Person ID Active Inactive
14589 06/012/007 10/14/2007
14589 09/22/2008 <NULL>
78569 05/02/2006 07/04/2007
75869 02/12/2008 01/22/2009
With this I could see if a certain date was Between [Active] And [Inactive] Or Date Is >[Active] and [Inactive] Is Null. I tried to build the table with a crosstab query (PersonID = Row, Status = Column, StatusDate = Value), but it would only give me on row for each person ID because it was looking at the Max or Min of StatusDate.
Any help is appreciated.
Greg