I am a newbie to SQL Server with a rather complex SQL task and none of the solutions I have found so far is fit for my problem below.
I have a database table that currently holds membership joining information (extract below) with one line for each year/period that a member have paid for membership; It is possible for a member to cancel their membership for one year/period and rejoin at a later date. We need to represent each continuous membership as one line such contents of Extract 1 below becomes Extract 2:
Extract 1
Member_No Start_Date End_Date
--------- ---------- --------
10 2010-01-01 00:00:00.000 2011-01-01 00:00:00.000
10 2011-01-01 00:00:00.000 2012-01-01 00:00:00.000
10 2012-01-01 00:00:00.000 2013-01-01 00:00:00.000
10 2013-01-01 00:00:00.000 2014-01-01 00:00:00.000
20 2005-01-01 00:00:00.000 2006-01-01 00:00:00.000
20 2006-01-01 00:00:00.000 2007-01-01 00:00:00.000
20 2007-01-01 00:00:00.000 2008-01-01 00:00:00.000
30 2005-01-01 00:00:00.000 2006-01-01 00:00:00.000
30 2006-01-01 00:00:00.000 2007-01-01 00:00:00.000
30 2007-01-01 00:00:00.000 2008-01-01 00:00:00.000
30 2008-01-01 00:00:00.000 2009-01-01 00:00:00.000
30 2009-01-01 00:00:00.000 2010-01-01 00:00:00.000
30 2010-10-13 00:00:00.000 2011-01-01 00:00:00.000
30 2011-01-01 00:00:00.000 2012-01-01 00:00:00.000
30 2012-01-01 00:00:00.000 2013-01-01 00:00:00.000
I need to replace contents of the above table with the below - there are many more records in the table in question and I would greatly appreciate any assistant anyone can offer:
Extract 2
Member_No Start_Date End_Date
--------- ---------- --------
10 2010-01-01 00:00:00.000 2014-01-01 00:00:00.000
20 2005-01-01 00:00:00.000 2008-01-01 00:00:00.000
30 2005-01-01 00:00:00.000 2010-01-01 00:00:00.000
30 2010-10-13 00:00:00.000 2013-01-01 00:00:00.000