MS-SQL – Write Stored Procedure Results to Table

I browsed the web looking for a way to write the results from one of my stored procedures to a table. There were quite a few ways to do it, however this one worked best for me:

IF OBJECT_ID(N'tempdb..#Temp') IS NOT NULL
BEGIN
    DROP TABLE #Temp
END
CREATE TABLE #Temp
          (Date_Flag          [varchar](12)
          ,Account_Code       [varchar](20)
          ,Calendar_Month     [datetime]
          ,Last_Receipt_Month [date]
          ,Last_Receipt_Date  [date]
          ,Last_Receipt_AMT   [money])
INSERT INTO #Temp
EXEC        [Database].[dbo].[Procedure];
SELECT * FROM #Temp
GO

I hope this helps.

God bless,
Colin

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s