satyajit
satyajit

Reputation: 2700

Inserting into table the values returned from stored procedure

I have a procedure which has a select statement as below:

CREATE PROCEDURE pr_test
as 
SELECT  * from SOURCETABLE

Can I insert into a temp table by executing the stored procedure pr_test by any chance?

Upvotes: 0

Views: 1091

Answers (2)

podiluska
podiluska

Reputation: 51494

You can use INSERT EXEC

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

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

Upvotes: 2

Vikram Jain
Vikram Jain

Reputation: 5588

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

Upvotes: 0

Related Questions