Hi,
I have a simple SQL Server 2008 table that contains history information relating to a salesPerson and their associated Office on given dates. The data is a bit like this:
ID_Salesman, ID_Office, StartDate, EndDate
1 2 2010-01-01 2010-01-05
1 2 2010-01-05 2010-01-10
1 3 2010-01-10 2010-01-15
1 2 2010-01-15 2010-01-30
As you can see, some of my rows overlap on the ID_Office front on certain dates. What I want to do is condense down the number of rows to 3 rows to be like this in a query:
ID_Salesman, ID_Office, StartDate, EndDate
1 2 2010-01-01 2010-01-10
1 3 2010-01-10 2010-01-15
1 2 2010-01-15 2010-01-30
So basically, when the StartDate is ordered , if the office id is the same as the previous row I want the end date to be amended.
For some reason am completely stuck on this one - a recursive query is needed?
Thanks,
MrPeds
I have a simple SQL Server 2008 table that contains history information relating to a salesPerson and their associated Office on given dates. The data is a bit like this:
ID_Salesman, ID_Office, StartDate, EndDate
1 2 2010-01-01 2010-01-05
1 2 2010-01-05 2010-01-10
1 3 2010-01-10 2010-01-15
1 2 2010-01-15 2010-01-30
As you can see, some of my rows overlap on the ID_Office front on certain dates. What I want to do is condense down the number of rows to 3 rows to be like this in a query:
ID_Salesman, ID_Office, StartDate, EndDate
1 2 2010-01-01 2010-01-10
1 3 2010-01-10 2010-01-15
1 2 2010-01-15 2010-01-30
So basically, when the StartDate is ordered , if the office id is the same as the previous row I want the end date to be amended.
For some reason am completely stuck on this one - a recursive query is needed?
Thanks,
MrPeds