I have the following Employee versioning table:
EmployeeId ManagerId DepartmentId StartDate EndDate
--------------------------------------------------------
45 2 56 2017-06-27 2018-02-07
45 3 98 2018-02-07 2018-08-25
45 3 55 2018-02-25 2018-08-25
45 6 44 2018-08-25 9999-12-31
I want to correct StartDate as below to avoid the overlap as below:
EmployeeId ManagerId DepartmentId StartDate EndDate
---------------------------------------------------------
45 2 56 2017-06-27 2018-02-07
45 3 98 2018-02-08 2018-08-25
45 3 55 2018-02-26 2018-08-26
45 6 44 2018-08-27 9999-12-31
The logic is like below for the first record the EndDate = 2018-02-07
, the next record will have EndDate + 1 day = 2018-02-08
. For the record with EndDate = StartDate
it will have in both The previous EndDate + 1.