SET ROWCOUNT 0
select * into #rrr from [OA_test].[dbo].[Company_KLFolder] ----新建临时表#rrr
declare @KLFGUID uniqueidentifier
declare @CGUID uniqueidentifier
declare @count int
declare @Sequence int
WHILE EXISTS(select [KLFGUID] from #rrr) ---遍历临时表
begin
SET ROWCOUNT 1 ---------设置影响行数为1
select @KLFGUID=cast([KLFGUID] as varchar(max)),@CGUID=CGUID from #rrr order by [CGUID] desc
print cast(@KLFGUID as varchar(max))
print cast(@CGUID as varchar(max))
set rowcount 0 ---------设置影响行数 不限制
select @Sequence = max([KLFSequence]) from [OA_test].[dbo].[Company_KLFolder] where CGUID = @CGUID
update Company_KLFolder set [KLFSequence] = (@Sequence+1) where [KLFGUID] = @KLFGUID
delete from #rrr where [KLFGUID] = @KLFGUID ------删除临时表中遍历过的本条数据
end
drop table #rrr ----删除临时表
select * into #rrr from [OA_test].[dbo].[Company_KLFolder] ----新建临时表#rrr
declare @KLFGUID uniqueidentifier
declare @CGUID uniqueidentifier
declare @count int
declare @Sequence int
WHILE EXISTS(select [KLFGUID] from #rrr) ---遍历临时表
begin
SET ROWCOUNT 1 ---------设置影响行数为1
select @KLFGUID=cast([KLFGUID] as varchar(max)),@CGUID=CGUID from #rrr order by [CGUID] desc
print cast(@KLFGUID as varchar(max))
print cast(@CGUID as varchar(max))
set rowcount 0 ---------设置影响行数 不限制
select @Sequence = max([KLFSequence]) from [OA_test].[dbo].[Company_KLFolder] where CGUID = @CGUID
update Company_KLFolder set [KLFSequence] = (@Sequence+1) where [KLFGUID] = @KLFGUID
delete from #rrr where [KLFGUID] = @KLFGUID ------删除临时表中遍历过的本条数据
end
drop table #rrr ----删除临时表