Hi!
Thank you in advanced for helping me.
I have been searching and tried a few examples but none gave me what I am looking for.
I have the following scenario:
Memberid | enrollment date | termination date
1111 | 9/1/2009 | 9/7/2009
1111 | 9/8/2009 | 9/30/2009
2222 | 9/1/2009 | 6/30/2010
2222 | 7/1/2010 | 4/30/2013
2222 | 8/1/2013 | 12/31/2013
2222 | 2/1/2013 | 12/31/2199
3333 | 11/1/2009 | 11/3/2009
3333 | 11/4/2009 | 6/30/2010
3333 | 7/1/2010 | 12/31/2199
4444 | 1/1/2013 | 12/31/2013
5555 | 11/1/2009 | 11/1/2009
6666 | 11/1/2009 | 11/3/2009
6666 |11/4/2009 | 3/31/2010
6666 | 4/1/2010 | 6/30/2010
6666 | 7/1/2010 | 8/31/2010
6666 | 9/1/2010 | 11/30/2010
6666 | 12/1/2010 | 4/30/2013
6666 | 5/1/2013 | 8/31/2013
I need to get only those members with no more than one gap in enrollment of up to 45 days during 1/1/2013 through 12/31/2013 inclusive or where the termination date is > than 12/31/2013 but with no more than 45 days gap.
So considering the above the member 1111 should be discarded since his enrollment is not during 2013.
Member 2222 would also be discarded since there is more than 45 days from termination date = 4/30/2013 and the next enrollment date being 8/1/2013.
Member 3333 should be included since only for the enrollment date = 7/1/2010 and termination date = 12/31/2199.
Member 4444 should be included since it's from 1/1/2013 through 12/31/2013.
Member 5555 should be discarded since it is not through 2013.
Member 6666 should not be included since the last termination date is 8/31/2013.
I hope I explained this clearly.
I'm looking for a solution that runs relatively fast and is easy to understand to run in SQL Server 2005 or 2008. Please explain the steps if you can.
I have already tried the following but it is not capturing all the necessry members:
Select distinct Memberid,MIN(enrollmentdate),MAX(terminationdate) from NJ_ADV_MEDICAID_WITH_DENTAL_BENEFIT
where DATEDIFF(DAY,enrollmentdate,terminationdate) <= 45
group by Memberid
HAVING DATEPART(YEAR,MAX(terminationdate)) = '2013'
Thank you so much in advanced!
TG
Thank you in advanced for helping me.
I have been searching and tried a few examples but none gave me what I am looking for.
I have the following scenario:
Memberid | enrollment date | termination date
1111 | 9/1/2009 | 9/7/2009
1111 | 9/8/2009 | 9/30/2009
2222 | 9/1/2009 | 6/30/2010
2222 | 7/1/2010 | 4/30/2013
2222 | 8/1/2013 | 12/31/2013
2222 | 2/1/2013 | 12/31/2199
3333 | 11/1/2009 | 11/3/2009
3333 | 11/4/2009 | 6/30/2010
3333 | 7/1/2010 | 12/31/2199
4444 | 1/1/2013 | 12/31/2013
5555 | 11/1/2009 | 11/1/2009
6666 | 11/1/2009 | 11/3/2009
6666 |11/4/2009 | 3/31/2010
6666 | 4/1/2010 | 6/30/2010
6666 | 7/1/2010 | 8/31/2010
6666 | 9/1/2010 | 11/30/2010
6666 | 12/1/2010 | 4/30/2013
6666 | 5/1/2013 | 8/31/2013
I need to get only those members with no more than one gap in enrollment of up to 45 days during 1/1/2013 through 12/31/2013 inclusive or where the termination date is > than 12/31/2013 but with no more than 45 days gap.
So considering the above the member 1111 should be discarded since his enrollment is not during 2013.
Member 2222 would also be discarded since there is more than 45 days from termination date = 4/30/2013 and the next enrollment date being 8/1/2013.
Member 3333 should be included since only for the enrollment date = 7/1/2010 and termination date = 12/31/2199.
Member 4444 should be included since it's from 1/1/2013 through 12/31/2013.
Member 5555 should be discarded since it is not through 2013.
Member 6666 should not be included since the last termination date is 8/31/2013.
I hope I explained this clearly.
I'm looking for a solution that runs relatively fast and is easy to understand to run in SQL Server 2005 or 2008. Please explain the steps if you can.
I have already tried the following but it is not capturing all the necessry members:
Select distinct Memberid,MIN(enrollmentdate),MAX(terminationdate) from NJ_ADV_MEDICAID_WITH_DENTAL_BENEFIT
where DATEDIFF(DAY,enrollmentdate,terminationdate) <= 45
group by Memberid
HAVING DATEPART(YEAR,MAX(terminationdate)) = '2013'
Thank you so much in advanced!
TG