sql查询出的语句能逐条的自动运行到存储过程吗

来源:百度知道 编辑:UC知道 时间:2024/06/14 23:55:43
例如我做了一个存储过程 存储过程有两个变量 运行的时候是exec a,b

现在我select出了好几个结果 a1,b1
a2,b2
能不能将a1,b1 a2,b2 逐行运行存储过程
最好用语句写出来
就象输出某条语句那样 select * from 表 where 条件
能写出具体的语句出来吗
不要理论的

可以用游标或生成自增临时表处理

如:

declare roy_cur cursor for
select a,b from 表 where 条件
declare @a int,@b int--定义类型
open roy_cur
fetch next from roy_cur into @a,@b
while @@fetch_status=0
begin
exec 存储过程 @a,@b]
fetch next from roy_cur into @a,@b
end
close roy_cur
deallocate roy_cur

可以的。。

可以
首先,你做了个存储过程A,需要a,b两个变量
你再做一个存储过程B,B就是循环执行存储过程A,循环的次数就是看你的
SQL语句select * from table 得到的记录条数