0

This code inserts the results of a stored procedure into a table. eg sp_configure etc.

CREATE TABLE #toto (v1 int, v2 int, v3 char(4), status char(6))
INSERT #toto (v1, v2, v3, status) EXEC dbo.sp_fulubulu(sp_param1)
SELECT * FROM #toto
DROP TABLE #toto

Is it possible to modify the code to include the parameter in the table?

CREATE TABLE #toto (v1 int, v2 int, v3 char(4), status char(6))
INSERT #toto (v1, v2, v3, status, parameter) EXEC dbo.sp_fulubulu(sp_param1), sp_param1
SELECT * FROM #toto
DROP TABLE #toto

Note, the parameter is not static.

Danny Rancher
  • 1,923
  • 3
  • 24
  • 43
  • You could add a `id INT IDENTITY PRIMARY KEY` column to your temporary table, insert the results of the SP as before, `SELECT @@IDENTITY` (or similar) into a variable, then use an UPDATE to add the value of the parameter to the same row you just inserted. Would that suffice? – Gord Thompson Oct 26 '17 at 15:53

1 Answers1

0

If your parameter/value what you want to insert along with sp result into table is static then you can use specify that parameter/value as Default value for column.

CREATE TABLE #toto 
(
v1 int, v2 int, v3 char(4), status char(6)**, parameter DataType DEFAULT(sp_param1)**)

INSERT #toto (v1, v2, v3, status) EXEC dbo.sp_fulubulu(sp_param1)

SELECT * FROM #toto

DROP TABLE #toto

https://www.w3schools.com/sql/sql_default.asp