declare @n table (id int);
insert into @n values (1), (2), (3), (5), (6), (7), (8), (15), (16), (20), (21), (22), (23), (30), (31), (55)
select diff, min(id) as range_from, max(id) as range_to
from (
select
id
, id - row_number() over (order by id) as diff
from @n
) x
group by diff
having min(id) <> max(id) -- опционально, если нужны именно диапазоны
order by diff