大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索
打印 上一主题 下一主题

SQL Server存储过程实现数据迴圈stored procedure foreach row table

[复制链接]
跳转到指定楼层
1#
发表于 2011-7-28 22:29:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
SQL Server存储过程实现数据迴圈 stored procedure foreach row returned by query
  1. declare @field1 int
  2. declare @field2 int
  3. declare cur CURSOR LOCAL for
  4.     select field1, field2 from sometable where someotherfield is null

  5. open cur

  6. fetch next from cur into @field1, @field2

  7. while @@FETCH_STATUS = 0 BEGIN

  8.     --execute your sproc on each row
  9.     exec uspYourSproc @field1, @field2

  10.     fetch next from cur into @field1, @field2
  11. END

  12. close cur
  13. deallocate cur
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-12-1 14:27 , Processed in 0.019281 second(s), 12 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表