select * into #ta from 序号表 where 1=2
while 1=1
begin
insert #ta select x.开始编号,y.结束编号
from 序号表 as x inner join 序号表 as y on y.开始编号=x.结束编号+1
if not exists(select * from #ta) break
delete 序号表
insert 序号表 select * from #a
end
select * from 序号表
declare @a int,@b int,@c int,@d int
while 1=1
begin
select top 1 @a=x.开始编号,@b=x.结束编号,@c=y.开始编号,@d=y.结束编号
from 序号表 as x inner join 序号表 as y on y.开始编号=x.结束编号+1
if @@rowcount=0 break
delete 序号表 where 开始编号=@c and 结束编号=@d
update 序号表 set 结束编号=@d where 开始编号=@a and 结束编号=@b
end
select * from 序号表