I have a temporal database table where some of the data is duplicated.
EmployeeId StartDate EndDate Column1 Column2
1000 2009/05/01 2010/04/30 X Y
1000 2010/05/01 2011/04/30 X Y
1000 2011/05/01 2012/04/30 X X
1000 2012/05/01 2013/04/30 X Y
1000 2013/05/01 NULL X X
As seen above there are some rows which are redundant and can be merged to form a single row without violating the data validity. I want to merge such rows wherever possible and the result should look like this
EmployeeId StartDate EndDate Column1 Column2
1000 2009/05/01 2011/04/30 X Y
1000 2011/05/01 2012/04/30 X X
1000 2012/05/01 2013/04/30 X Y
1000 2013/05/01 NULL X X
How can this be achieved?
Try this
Note: TEMP is the table with mentioned columns
Try this if you can ensure that all the start date and end date are continuous :