 | 存储过程A里,将存储过程B的结果集存到A的临时表或者表变量里
CREATE TABLE test1
(
a VARCHAR(20)
)
GO
CREATE TABLE test2
(
a VARCHAR(20)
)
GO
INSERT INTO test1 VALUES('aaa')
GO
CREATE PROCEDURE sp_test
AS
SELECT * FROM test1
GO
EXEC sp_test
GO
INSERT INTO test2 EXEC('EXEC SP_TEST');
GO
SELECT * FROM test2
GO
sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
alter procedure sp_test2 as
SELECT *
INTO #MyTable --( can be either a temp table or perm table,不用事先知道其Schema,这正是你想要的)
FROM OPENROWSET('SQLNCLI', 'server=.;trusted_connection=yes',
'exec IPSUNU9DB_20130425.dbo.SP_TEST')
select * from #MyTable
exec sp_test2
| |