游标更新字段脚本

来源:互联网 发布:mac 拖拽文件 编辑:程序博客网 时间:2024/05/17 03:07

declare test  cursor for
select studentcode from student where classid =25541 order by studentcode
declare @studentcode nvarchar(16),@ID2 nvarchar(10)
declare @ii int
set @ii=1
open test
fetch next from test into @studentcode
while @@fetch_status=0
begin
    select @ID2=@ii--substring(@studentcode,16,2)

    update student
    set studentname=studentname+@ID2
    where studentcode=@studentcode
    set @ii=@ii+1
    fetch next from test into @studentcode
end
close test
deallocate test
go 

原创粉丝点击