SQL 游标

来源:互联网 发布:360°全景图js 编辑:程序博客网 时间:2024/05/21 09:56

/** 这个用于循环修改表中的字段值 **/

declare  @a nvarchar(50),@b uniqueidentifier
declare _codeCursor cursor for
 SELECT UnitCode,id FROM RmsOrganization
open _codeCursor
 fetch next from _codeCursor into @a, @b
 while (@@fetch_status = 0)
  begin
 update RmsActivity set UnitCode=@a where OrganizationId=@b
   fetch next from _codeCursor into @a, @b
  end
close _codeCursor
deallocate _codeCursor