将从存储过程返回的值插入表中

时间:2012-10-05 09:42:25

标签: sql sql-server-2008-r2

我有一个过程,其中有一个如下所示的选择语句:

CREATE PROCEDURE pr_test
as 
SELECT  * from SOURCETABLE

我可以通过任何机会执行存储过程pr_test来插入临时表吗?

2 个答案:

答案 0 :(得分:2)

您可以使用INSERT EXEC

 declare @t results (field1 int, ....)

 insert @t (field1,...)
 exec pr_test 

答案 1 :(得分:0)

CREATE PROCEDURE pr_test 
as
begin

CREATE TABLE #TibetanYaks(
YakID int,
YakName char(30) )

INSERT INTO #TibetanYaks (YakID, YakName)
SELECT  YakID, YakName
FROM    dbo.Yaks
WHERE   YakType = 'Tibetan'

-- Do some stuff with the table

drop table #TibetanYaks


end