sql server 脚本 游标的使用

原文链接:http://www.fengyachao.com/archives/57


declare @zorder int,@a001000 varchar(20),@a001000temp varchar(20),@id int

set @zorder = 1
set @a001000temp = '@#$%'
declare cur Cursor for
select a001000,id from table_name order by a001000,zorder
open cur
fetch next from cur into @a001000,@id
while @@fetch_status=0
begin
if(@a001000temp != @a001000)
begin
set @zorder = 1
set @a001000temp=@a001000
end
update table_name set zorder=@zorder where a001000=@a001000 and id=@id
set @zorder=@zorder+1
fetch next from cur into @a001000,@id
end
close cur
deallocate cur
阅读更多
文章标签: sql server 脚本 table
个人分类: sql server
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭