I am trying to figure out the best way to determine global and local mins and maxs for a data set. I think there has got to be an easy way to do this but I cannot figure it out.
I am using Sql Server 2008.
Lets say I have a data set of subscription dates for users.
Start Date Stop Date PersonID
12/31/2007 3/31/2008 1
3/31/2008 6/30/2008 1
6/30/2008 9/30/2008 1
2/28/2008 3/31/2008 2
3/31/2008 4/30/2008 2
7/31/2008 8/31/2008 2
5/31/2008 6/30/2008 3
I know some of these dates are quarterly and some are monthly.
The end result should be:
StartDate StopDate PersonID
12/31/2007 9/30/2008 1
2/28/2008 4/30/2008 2
7/31/2008 8/31/2008 2
5/31/2008 6/30/2008 3
I just want to find all the possible contiguous segments and do this without looping or a cursor.
Any ideas?