Members with Continuous Enrollment calculation

Hi Everyone,

I am trying to implement a query to identify the continuous enrollment for 3 or 6 months for a member based on the event date but not getting the exact answer. the event date will be very for each member.

Here is the sample input
1

the output should be something like this, the Event date and [Event date +3] should be available between effective and end date

PatientID Event date [Event date +3] effective date end date [3 months CE] [6 months CE]
1 1/26/2017 4/26/2017 1/1/2017 1/31/2017 1
1 1/26/2017 4/26/2017 2/1/2017 12/30/2017 1
2 1/26/2017 4/26/2017 1/1/2015 12/31/2017 1
2 2/8/2017 5/9/2017 1/1/2015 12/31/2017 1
3 1/4/2017 4/4/2017 1/1/2014 1/31/2017 0
3 1/4/2017 4/4/2017 3/1/2017 4/1/2017 0
4 6/4/2016 9/2/2016 1/1/2014 1/31/2016 1
4 6/4/2016 9/2/2016 3/15/2016 5/14/2016 1
4 6/4/2016 9/2/2016 6/2/2016 12/31/2017 1
5 6/4/2016 9/2/2016 3/15/2016 5/14/2016 0
5 6/4/2016 9/2/2016 6/2/2016 8/31/2017 0

thanks,
RR

Maybe I'm slow but I'm not understanding you requirement. Please give more info Create table statement, insert statement with your sample datalike this:

CREATE TABLE #t(Col1 datatype,...);
Insert #t values(….),(…);