2012-10-05 159 views
0

返回的值我有有如下一個SELECT語句的過程:通過任何機會執行存儲過程pr_test將插入到表從存儲過程

CREATE PROCEDURE pr_test 
as 
SELECT * from SOURCETABLE 

我可以插入到一個臨時表?

+0

[你嘗試過什麼(http://whathaveyoutried.com)?請發佈您當前的SQL嘗試,並解釋哪些工作不正常,以及您卡在哪裏。 – Oded

+0

可能的重複問題http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure –

回答

2

您可以使用INSERT EXEC

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

insert @t (field1,...) 
exec pr_test 
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