首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

如何样把存储过程返回的表 并 起来

2012-03-27 
怎么样把存储过程返回的表 并 起来select * from usersunionselect* from users这样写是对的exec p_select

怎么样把存储过程返回的表 并 起来
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临时表的结果就可以了
[解决办法]
探讨

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

热点排行