begin
--申明变量
declare @htbh char(100)
--赋值变量
--set @htbh=1
--申明游标
declare order_cursor cursor
for (select htbh from #htyhkje where cursorstatus=0)--循环条件
--打开游标--
open order_cursor
--开始循环游标变量--
fetch next from order_cursor into @htbh
while @@FETCH_STATUS = 0 --返回被 FETCH语句执行的最后游标的状态--
begin
print @htbh;
exec [pro_bh001] @htbh --执行存储过程,这部分可以做很多事,update,insert等
update #htyhkje set cursorstatus=1 where htbh=@htbh
fetch next from order_cursor into @htbh --转到下一个游标,没有会死循环
end
close order_cursor --关闭游标
deallocate order_cursor --释放游标
end
Go