0

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?

Oded
  • 489,969
  • 99
  • 883
  • 1,009
satyajit
  • 2,540
  • 11
  • 33
  • 44
  • [What have you tried](http://whathaveyoutried.com)? Please post your current SQL attempts and explain what is not working and where you are stuck. – Oded Oct 05 '12 at 09:45
  • Possible duplicate question http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure – Aleksandr Fedorenko Oct 05 '12 at 10:22

2 Answers2

2

You can use INSERT EXEC

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

 insert @t (field1,...)
 exec pr_test 
podiluska
  • 50,950
  • 7
  • 98
  • 104
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
Vikram Jain
  • 5,498
  • 1
  • 19
  • 31