我需要批量运行存储过程

时间:2011-09-04 16:53:33

标签: sql-server-2008

我有一个更新表中超过2000行的过程。

我需要让程序批量运行。我希望它在前10行然后在下10行运行,依此类推。请问我该怎么做。

1 个答案:

答案 0 :(得分:0)

类似的东西:

declare @id int
declare c cursor for 
  select top 10 id 
  from table 
  where (needs updating) = 1

open c 
fetch next from c into @id
while @@fetch_status = 0
begin

  update table 
  set 
    (needs to be set) = (value to set), 
    (needs updating) = 0      
  where id = @id

  fetch next from c into @id

end