Save Stored Proc Results

  • I have a stored proc that returns a resultset.  I would like to call that proc from another proc inserting the results into a temp table.  The code I'm using is below.  Is there another way to do this without creating the structure for #t?  Sort of like a SELECT INTO.

    create table #t (Cusip char(20),

          SecPrice float,

          CurFactor float,

          PrevFactor float,

          CurCoupon float,

          PrevCoupon float,

          CurAccrDate datetime,

          PrevAccrDate datetime,

          USDRate float,

          DolsPerPt float)

     --exec spCurrentInfoAsOfDate @AsOfDate

     insert #t exec spCurrentInfoAsOfDate @AsOfDate

  • Have a look at SELECT INTO in BOL.


    Kindest Regards,

  • I have not been able to do this without creating the table ahead of time.




    Curtis Smith
    SQL Server DBA
    Well in worked in Theory ...

  • If you want to do this you can convert your SP to a UDF that returns a table. You will then be able to do something like the following

    SELECT * into #Foo

    FROM dbo.MyUDF(@Param)

    SELECT * FROM #Foo




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

  • if you follow the udf path you may as well don't create the table at all

    just use:

    SELECT * FROM dbo.MyUDF(@Param)


    * Noel

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply