sqlserver 游标的简单示例
程序员文章站
2023-11-17 19:58:52
declare @id varchar(20) declare @name varchar(20) declare cur cursor for select substr...
declare @id varchar(20)
declare @name varchar(20)
declare cur cursor for
select substring(id,0,7) as id,name from temp1
open cur
fetch next from cur into @id,@name
while @@fetch_status=0
begin
update temp set [c3]=@name where [id] like @id+'%'
fetch next from cur into @id,@name
end
close cur
deallocate cur
declare @name varchar(20)
declare cur cursor for
select substring(id,0,7) as id,name from temp1
open cur
fetch next from cur into @id,@name
while @@fetch_status=0
begin
update temp set [c3]=@name where [id] like @id+'%'
fetch next from cur into @id,@name
end
close cur
deallocate cur