如何读取存储过程中返回的多表集数据

wheatlee 2007-09-03 02:23:32
如何读取存储过程中返回的多表集数据?

比如一个存储过程[GetInfo]
里面的sql语句是这样的:
Select * from tableA
Select * from tableB
...
Select * from tableN

当我exec [GetInfo]时,会返回多个表集。

我需要把每个表集都分别插入它所对应的一张临时表里,请问怎么做?
谢谢各位!
...全文
370 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wheatlee 2007-09-04
  • 打赏
  • 举报
回复
既然是这样那么你就把结果返回到前台应用程序去操作吧
-----------------------------------------------------
这是目前我能想到的最好的办法。

不过我还是想不写前台程序,再数据库一层进行处理。因为我的工作是要检查存储过程返回的值是否正确。
hb_gx 2007-09-03
  • 打赏
  • 举报
回复
因为存储过程只能调用,不能修改的。我们这里要求的。
-----------------------------------------------------

既然是这样那么你就把结果返回到前台应用程序去操作吧
nextflying 2007-09-03
  • 打赏
  • 举报
回复
用函数

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
































--0725计划查询
--由于Foreign_type始终为1,故此忽略该参数,两种计划模式下将使用不同的输入参数


ALTER FUNCTION CountOneSimsPlan(@plan_id int,@plbgn char(10),@plend char(10),@intBureauID int)

RETURNS @CountOneSimsPlan TABLE
(
planed int,
complete int
)
AS
BEGIN

declare @ctemp2 char(10),@ctemp1 char(10),@detail_type int,@Foreign_id int,@foreign_type int--,@pen_id char(10)
declare @temp table
(
button_id char(12),
nd_button char(12),
pen_id char(10)
)
select @detail_type = detail_type, @foreign_type = foreign_type, @foreign_id = foreign_id from [plan] where id = @plan_id and bureau_id = @intBureauID and del_tag = 0

select @ctemp1=dbo.datetochar(@plbgn)
select @ctemp2=dbo.datetochar(@plend+' 23:59')
if (@Detail_type=0)
begin
insert @CountOneSimsPlan
values(0,0)
end
else if (@Detail_type=1)--此时计划编号失去作用,故函数没有调用它
begin
insert @temp
select dev.xinxiniu,nd.button_id,nd.pen_id
FROM dbo.team_dev td INNER JOIN dev on td.dev_id=dev.id
and td.del_tag=0 and dev.del_tag=0
and td.bureau_id=dev.bureau_id
and td.bureau_id=@intBureauID
and td.zubianhao=@Foreign_id--@Foreign_id
--and td.subunit_id=@subunit_id
inner join station s on dev.jizhanid=s.id
and s.del_tag=0
left join nudity_data nd on dev.xinxiniu=nd.button_id
and time > @ctemp1 and time<@ctemp2



insert @CountOneSimsPlan
select count(distinct button_id) ,0 from @temp
update @CountOneSimsPlan set complete=(select count(distinct nd_button) from @temp)


end
else if (@detail_type=2)
begin
insert @temp
select dev.xinxiniu,nd.button_id,nd.pen_id
from dbo.plan_detail pd inner join dev on pd.dev_id=dev.id
and pd.del_tag=0 and dev.del_tag=0
and pd.bureau_id=dev.bureau_id
and pd.bureau_id=@intBureauID
-- and pd.Foreign_id=@Foreign_id
--plan_id,bureau_id可以唯一标识一个计划么?,可以做到可以的
and pd.plan_id=@plan_id
inner join station s on dev.jizhanid=s.id
and s.del_tag=0
left join nudity_data nd on dev.xinxiniu=nd.button_id
and time > @ctemp1 and time<@ctemp2

insert @CountOneSimsPlan
select count(distinct button_id) ,0 from @temp
update @CountOneSimsPlan set complete=(select count(distinct nd_button) from @temp)



end

RETURN
END






































GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

如上实例
wheatlee 2007-09-03
  • 打赏
  • 举报
回复
各位兄弟,我的意思是不改动存储过程。
因为存储过程只能调用,不能修改的。我们这里要求的。
Limpire 2007-09-03
  • 打赏
  • 举报
回复
--改存储过程,每次只返回一个结果集:

create table #temp1 (字段列表)
insert #temp1 exec GetInfo 参数列表

create table #temp2 (字段列表)
insert #temp2 exec GetInfo 参数列表

create table #temp3 (字段列表)
insert #temp3 exec GetInfo 参数列表

...
winjay84 2007-09-03
  • 打赏
  • 举报
回复
直接在这个存储过程中处理好了。

-- 你的语句
比如一个存储过程[GetInfo]
里面的sql语句是这样的:
insert into 临时表名A(tableA结构) -- 这里改动
Select * from tableA
insert into 临时表名B(tableB结构) -- 这里改动
Select * from tableB
...
insert into 临时表名N(tableN结构) -- 这里改动
Select * from tableN
LPQ8306586 2007-09-03
  • 打赏
  • 举报
回复
你的意思是存贮过程执行后再获得几个表的数据?
似乎不大可能,应该要在存贮过程里读表时就要插入临时表了。。。
fa_ge 2007-09-03
  • 打赏
  • 举报
回复
Select * into #tableA from tableA
Select * into tableB from tableB
...
Select * into tableB from tableN
wheatlee 2007-09-03
  • 打赏
  • 举报
回复
难道不支持逐个获取存储过程的多个结果集?不至于。?

什么意思呀?
子陌红尘 2007-09-03
  • 打赏
  • 举报
回复
难道不支持逐个获取存储过程的多个结果集?不至于。

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧