Groups | Blog | Home
all groups > sql server (microsoft) > december 2004 >

sql server (microsoft) : Inserting into a TempDB table via a stored Proc


NonNB
12/21/2004 5:49:33 AM
Hi

Is there a way in MS SQL 2000 to insert the results of a Sproc into a
#temp table without having to create it up front ?

e.g. instead of
Create table #tmp(ID INT)

insert into #tmp
exec dbo.myProc

(where dbo.myProc returns several rows of a single INT field)

do something like

select "exec dbo.myProc"
into #tmp

i.e. so don't have to go through the motions of manually creating the
Temp table??

Thanks in Advance

Stuart
Ross Presser
12/21/2004 12:41:02 PM
[quoted text, click to view]

No, there is not.

If it's a big annoyance, you could always wrap the table creation + call
into another stored procedure:

CREATE PROCEDURE CallAndInsert ()
AS

CREATE TABLE #tmp(ID INT)

INSERT INTO #tmp
NonNB
12/22/2004 12:17:57 AM
Thanks Ron. Will encapsulate the creation as you suggest.

Cheers
Stuart
JayEs
1/7/2005 7:26:46 PM
Why not put the create table statement in MyProc? It seems to me that MyProc
is the SP that will work with the #table. Might as well create it in the SP
using it.

AddThis Social Bookmark Button