declare @period table (
name varchar(10) ,
startdate date,
enddate date)
insert into @period values
('ddd' ,'2019-01-01','2019-05-01'),
('ddd' ,'2019-05-02','2019-06-07'),
('ddd' ,'2019-06-10','2019-09-04'),
('ddd' ,'2019-09-05','2999-12-31'),
('aaa' ,'2019-09-01','2019-09-10'),
('aaa' ,'2019-09-12','2019-12-31'),
('aaa' ,'2020-01-01','2020-12-31')
select * from @period order by 1,3
SELECT period.name, period.startdate, period.enddate
FROM @period as period
LEFT OUTER JOIN @period AS period_end ON period.name = period_end.name
AND DATEADD(dd, 1, period.enddate) = period_end.startdate
WHERE (period_end.startdate IS NULL)
AND (period.enddate <> (SELECT MAX(enddate) FROM @period AS period_last
WHERE (name = period.name)))
order by name