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 序号表
非常希望各位注意:不要受到3GL编程语言的狭隘思维方式的束缚。
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 序号表
非常希望各位注意:不要受到3GL编程语言的狭隘思维方式的束缚。
解决方案 »
- 求一个sql语句
- 怎么锁住一条记录
- 返回累计销售总金额小于1000的所有记录
- libin_ftsafe(子陌红尘)请进
- 复杂的唯一查询
- SqlServer2000:如何在自定义函数里调用存储过程
- SQL server 以Excel导入导出数据的问题
- 帮忙解决下,这个触发器怎么写?我写的实现不了啊
- 100分求解:怎样从ACCESS中把日期为本月的数据查询出来?急。
- "The datebase you are attempting to restore was bacled up under a different sot order ID (52) then the one currently running on
- 很急!!在线等!谢谢先!!
- 怎么写语句查出一列中重复的记录
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 序号表如果“开始编号”或者“结束编号”有重复,要首先处理一下,将重复记录只留下一个。