2014-06-26 29 views
0

我想知道是否有可能從結果的特定列從存儲過程插入到表?只插入特定的列從存儲過程結果

喜歡的東西:

declare @temp as table(
id int 
) 

insert @temp 
exec getlistofStudents --returns multiple columns 

這僅是一個例子,感謝您的幫助..

+0

可能重複的[如何選擇\ * INTO \ [臨時表\] FROM \ [存儲過程\]](http://stackoverflow.com/questions/653714/how-to-select-into -temp-表從存儲過程) –

+0

你可以從存儲過程不是一個單一的列中獲取所有列.. – Azar

回答

1

你可以採取2步方法。第一INSERT INTO一個#TempTable,然後填充與另一插入@TempVariable,選擇所述單個列。

DECLARE @temp AS TABLE 
(
    ID int 
); 

CREATE TABLE #tempTable1 
(
    Column1 int, 
    Column2 int 
); 

INSERT INTO #tempTable1 
Exec getlistofStudents 

INSERT INTO @temp 
SELECT Column1 FROM #tempTable1