Reputation: 19688
If I have a stored procedure like this:
CREATE Procedure [dbo].[insertIntoTableX]
-- table_name as there are three tables with the same schema...
@table_name varchar(200),
-- all the other variables for the columns
@column_1 = NULL,
@column_2 = NULL,
@column_3 = NULL,
@column_4 = NULL,
@column_5 = NULL
AS
BEGIN TRY
SET NOCOUNT ON
INSERT INTO @table_name (column_1, column_2, column_3, column_4, column_5)
VALUES (@column_1, @column_2, @column_3, @column_4, @column_5)
END TRY
BEGIN CATCH
-- ....
END CATCH
If I call it with Execute insertIntoTableX (1,2,3,4)
, the results will be [1
,2
,3
,4
,NULL
] because the fifth was set to null by the default values in the stored procedures.
How do I call it with a missing parameter? E.g. if want the result to be [NULL
,NULL
,3
,NULL
,5
]?
Upvotes: 0
Views: 840
Reputation: 1269923
You would call the stored procedure with named parameters. For instance:
exec [dbo].[insertIntoTableX] @column_3 = 3, @column_5 = 5;
Upvotes: 3