如果我有这样的存储过程:
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
如果我使用Execute insertIntoTableX (1,2,3,4)
调用它,结果将是[1
,2
,3
,4
,NULL
],因为第五个被存储过程中的默认值设置为null。
如何使用缺少的参数调用它?例如。如果希望结果为[NULL
,NULL
,3
,NULL
,5
]?
答案 0 :(得分:3)
您可以使用命名参数调用存储过程。例如:
exec [dbo].[insertIntoTableX] @column_3 = 3, @column_5 = 5;