Re: Inserting into a TempDB table via a stored Proc

From: Ross Presser (rpresser_at_imtek.com)
Date: 12/21/04


Date: Tue, 21 Dec 2004 12:41:02 -0500

On 21 Dec 2004 05:49:33 -0800, NonNB wrote:

> 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

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
EXEC dbo.myProc



Relevant Pages

  • Re: [PATCH] Documentation update sched-stat.txt
    ... int *cpus, int *domains, ... fprintf(stderr, "file format error 0\n"); ... if (tmp!= SCHEDSTAT_VERSION) { ... printf(" %.3f%% of remote wakeups come from domain%d\n", tmp, i); ...
    (Linux-Kernel)
  • About: An INSERT EXEC statement cannot be nested.
    ... When I use following sql to get data in stored procedure, ... create table #tmp (aa int, ...
    (comp.databases.ms-sqlserver)
  • Re: SELECT result from a store procedure
    ... Sending output of stored procedure to table without pre-creating table: ... from openquery (, 'exec sp_who') ... spid int null, ...
    (microsoft.public.sqlserver.programming)
  • Re: Help on TI C64x+
    ... int corrOut; ... short demod(short *restrict in, short *restrict qu, unsigned char ... tmp = _pack2; ... In this case the compiler will remove the dead code. ...
    (comp.dsp)
  • Re: Help on TI C64x+
    ... int corrOut; ... short demod(short *restrict in, short *restrict qu, unsigned char ... tmp = _pack2; ... In this case the compiler will remove the dead code. ...
    (comp.dsp)