日期:2014-05-18  浏览次数:20491 次

怎么样把存储过程返回的表 并 起来
select * from users union select* from users
这样写是对的

exec p_select 也可以执行

exec p_select union exec p_select 这样就报错了,请问该怎么写

------解决方案--------------------
放临时表再union all
create table #T1(collist...)
insert #T1 exec P_select ...
create table #T2(collist...)
insert #T2 exec P_select ...
go
select * from #t1
union all
select * from #t2
------解决方案--------------------
可以用临时表,一个就行

create table #tb (结果集所有字段)

insert into #tb exec P_select ...
insert into #tb exec P_select
------解决方案--------------------
SQL code

用表和临时表都行
insert into #tb exec  过程
insert into tb exec 过程

select * from #tb union select * from tb

------解决方案--------------------
探讨
放临时表再union all
create table #T1(collist...)
insert #T1 exec P_select ...
create table #T2(collist...)
insert #T2 exec P_select ...
go
select * from #t1
union all
select * from #t2

------解决方案--------------------
union不能直接这样用,可以用临时表分别存储结果,然后再通过union临时表的结果就可以了
------解决方案--------------------
探讨

临时表创建好了后,需要写代码释放吗?