游标是个好东西,最大的用处在于可以将表中的数据全部取出来,修改了再存进去。

--先定义两个变量用来保存取出的数据
declare  @id  int
declare  @name  nvarchar(20)

declare  cursor1  cursor  for     ---定义游标cursorl
select  ID, Name from Test.dbo.Emp    ---使用游标对象

open cursorl1  ---打开游标

fench  next  from  cursor1   into  @id , @name   ---将游标向下移一行,将数据存入变量中

while  @@fench_status = 0

begin

     update  Test.dbo.Emp  set  Name = name  + "hello world"  where  ID = @id

     fench next from cursor1  into @id, @name

end

close cursor1

相关文章:

  • 2021-12-22
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2022-02-01
  • 2021-08-10
  • 2021-09-17
  • 2022-12-23
  • 2022-02-05
  • 2021-05-26
相关资源
相似解决方案