用游标处理数据比较灵活,但速度慢!可以使用临时表+循环来代替游标以提高效率
create procedure abc as
declare @t table(row int identity,key int)
declare @p int
insert @t select * from myTableOrView where .....
set @p=@@identity
declare @key
while @p>0 begin
set @key=(select key from @t where row=@p)
exec doProcessWithKey @key
@p=@p-1
end --while