troubleshooting Question

determine if date is consecutive by person ID

Avatar of jvoconnell
jvoconnell asked on
Microsoft SQL Server
7 Comments1 Solution159 ViewsLast Modified:

I have a table with a member id and an eligibility date. I need to create a record by member id with the minimum eligibility date and max eligibility date where the dates are consecutive (by month). The logic is also that there can be be a one month gap to be considered "consecutive". When the dates aren't consecutive, it would be a new record.

MemberID        EligibilityDT
XYZ                         1/1/2014
XYZ                         2/1/2014
XYZ                        4/1/2014
XYZ                        7/1/2014

The desired output would be:

MemberID      StartDT       EndDT
XYZ                1/1/2014      4/1/2014
XYZ               7/1/2014        7/1/2014

My logic is cursor processing. I am looping thru by member and comparing a date variable to the next date variable by DateDiff. Then swithcing the value of the date variable vs. the next date.

Am I  even correct that cursor processing is the way to go. It just seems like there has to be an easier way.
The table has 10M rows. Any insight is appreciated.

SQL Server 2012 if that matters.

Thank you.
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros