mssql 存储过程调用另一个存储过程中的结果的方法分享

摘要:
下文将分享"一个存储过程"中如何调用"另一个存储过程的返回结果",并应用到自身的运算中

在实际开发中,我们经常会遇到在一个存储过程中调用另一个存储过程的返回结果(存储过程相互应用),

实现思路:主要采用临时表将存储过程返回的结果集进行存储,然后供另一个存储过程应用。
如下所示:

create proc pr_b  
  @a int,@b int
as
begin
 select @a as a @b as b 
 union all 
 select @a+1 as a @b+1 as b 
end
go

-----创建存储过程pr_a,并调用存储过程pr_b的返回结果
create proc pr_a  
as
begin
  create table #t (a int,b int) 
  insert into #t (a,b)
  exec pr_b 120,188

  select * from #t 

  truncate table  #t
  drop       table  #t
end
go

这是一篇来自"猫猫小屋"的文章。

猜你喜欢

转载自blog.51cto.com/13806592/2287664