Store SP data in temp table

Mike 341 Reputation points
2020-10-19T23:34:22.207+00:00

Hello - I have the following SP and want to save the result of this SP in temp (#temp) table. Is it possible to save the result of SP's result data into #temp table?

Exec sales2021 @AB='ADC', @AC='DFG'

Developer technologies Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. MelissaMa-MSFT 24,221 Reputation points
    2020-10-20T00:54:32.607+00:00

    Hi @Mike

    Please refer below:

    -- Creating Temporary Table  
    CREATE TABLE #temp(  
    	Col1 [nvarchar](650) NULL,  
    	Col2 [nvarchar](255) NULL  
    )  
    GO  
      
    --Inserting Records from Stored procedure to Temporary Table  
    INSERT INTO #temp  
    Exec sales2021 @AB='ADC', @AC='DFG'  
    GO  
      
    -- Selecting Records from Temporary Table  
    SELECT * FROM #temp  
    

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.