Danny Rancher
Danny Rancher

Reputation: 2005

How to include parameter when inserting stored procedure results into table?

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.

Upvotes: 0

Views: 110

Answers (1)

Gurpreet Singh
Gurpreet Singh

Reputation: 109

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

Upvotes: 0

Related Questions