;with
cte as
(
select EMPLOYEE, POSITION, EFFECT_DATE, END_DATE,
rn= row_number() over (partition by EMPLOYEE order by EFFECT_DATE)
from tbl
),
rcte as
(
select EMPLOYEE, POSITION, EFFECT_DATE, END_DATE, rn, grp = 1
from cte
where rn = 1
union all
select c.EMPLOYEE, c.POSITION, c.EFFECT_DATE, c.END_DATE, c.rn,
grp = case when r.END_DATE = dateadd(day, -1, c.EFFECT_DATE)
then r.grp
else r.grp + 1
end
from rcte r
inner join cte c on r.EMPLOYEE = c.EMPLOYEE
and r.rn = c.rn - 1
)
select EMPLOYEE, POSITION, EFFECT_DATE = min(EFFECT_DATE), END_DATE = max(END_DATE)
from rcte
group by EMPLOYEE, POSITION, grp
KH
Time is always against us