views:

29

answers:

1

As a follow-up to my previous question I would like to know if there is a simple way of doing the following (which doesn't compile):

CREATE TABLE #PV ([ID] INT, [Date] DATETIME, Dis FLOAT, Del Float, Sold Float)
INSERT #PV @ID, exec GetPVSummaryReport @ID, @PID, @From, @To

The reason is I need to join #PV onto another table by [ID], but the original stored procedure doesn't have the necessary parameter.

Updating the SP is difficult (not impossible) as the code is 'out-in-the-wild' and I'd prefer not to have 'GetPVSummaryReport2' (which we already have several of already).

+2  A: 
CREATE TABLE #PV ([Date] DATETIME, Dis FLOAT, Del Float, Sold Float)
INSERT #PV EXECUTE GetPVSummaryReport @ID, @PID, @From, @To
SELECT @ID as [ID], * FROM #PV

Or

CREATE TABLE #PV ([ID] INT NULL, [Date] DATETIME, Dis FLOAT, Del Float, Sold Float)
INSERT #PV ([Date], Dis, Del, Sold) EXECUTE GetPVSummaryReport @ID, @PID, @From, @To
UPDATE #PV SET [ID] = @ID
SELECT * FROM #PV
Christian Hayter
I was so focused on getting the table into via insert I didn't consider the use of update!
graham.reeds
+1. I missed that!
Mitch Wheat