34,594
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据: tb
if object_id('tb')is not null drop table tb
go
create table tb(tb1Column1 varchar(1),tb1Column2 int,tb1Column3 varchar(2))
insert into tb
select 'a',1,'a1' union all
select 'a',2,'a2' union all
select 'a',3,'a3' union all
select 'a',3,'a4' union all
select 'a',4,'a5' union all
select 'b',1,'b2' union all
select 'b',1,'b4' union all
select 'b',1,'b6' union all
select 'b',1,'b1'
--> 测试数据:tb2
if object_id('tb2')is not null drop table tb2
go
create table tb2(tb1Column1 varchar(1),tb1Column2 int,tb1Column3 varchar(2))
if object_id('pp')is not null drop proc pp
go
create proc pp ---proc
as
select top 3 * from tb
go
---------------------------------------
insert tb2 exec pp
select * from tb2
tb1Column1 tb1Column2 tb1Column3
---------- ----------- ----------
a 1 a1
a 2 a2
a 3 a3
(3 行受影响)
如果你存储过程里面单单是SELECT而没有用其他临时表的话, 可以考虑直接用视图完成
SELECT XX ... FROM TB1
UNION ALL
SELECT YY .. . FROM TB2