Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Count of Months in Historical Spans

Author  Topic 

pcg2007
Starting Member

2 Posts

Posted - 2010-10-23 : 10:48:50
Hi,

I am working with a table that shows a member's enrollment in a program using enrollment spans with start and end dates.

For example, a member may have two spans:

Plan - Start - End
Plan A - Jan 09 - Jul 09
Plan A - Aug 09 - Oct 10

I need to write a query that tells me how many consecutive months this person has been enrolled for. You can see in this example, the person has 2 spans, but there was no gap in between. So although the current span started in August 2009, this member has been enrolled consecutively since January 2009.

Any ideas how this can be done?

Thank You

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-03 : 10:10:58
Does the table have any primary/unique key?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -