日期:2014-05-17  浏览次数:20423 次

sqlserver存储过程返回table如何实现?
我有个存储过程p_abc,其他很多存储过程都会调用这个存储过程的计算结果,请问我如何在sql中在其他存储过程中获取p_abc中的最后返回table?


create proc p_abc
@i int
as
--中间有个非常复杂的计算
select * from #tmp where fid=@i   --我想在外部存储过程中获取这个table

------解决方案--------------------
把临时表该成正式的表
------解决方案--------------------
CREATE PROC p_abc
  @PA1 INT,
  @PA2 INT,
  @PA3 INT OUTPUT
AS
  SET @PA3 = @PA1 + @PA2
GO

DECLARE @PA4 INT
EXEC p_abc 2,4,@PA4  OUTPUT
SELECT @PA4
 
------解决方案--------------------
create proc p_abc @i int
as
--中间有个非常复杂的计算 
select * from #tmp where fid=@i 
go



create proc p_test @i int
as
set nocount on

create table #temp(.....)
insert into #temp
exec p_abc @i  --执行这个语句后返回一个table,把这个返回结果插入到临时表

go

------解决方案--------------------
你在程序中如果调用这个存储过程一般是获取到的dataset,而一个dataset包含多个datatable,这样取就行

DataSet ds=new DataSet()
ds.Tables[1]