2015-06-21 69 views
0

如果我有这样一个存储过程:执行存储过程缺少不同的参数调用

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)调用它,其结果将是[1234NULL]因为第五个被存储过程中的默认值设置为null。

如何使用缺少的参数调用它?例如。如果想要结果是[NULL,NULL,3,NULL,5]?

回答

3

您将使用命名参数调用存储过程。例如:

exec [dbo].[insertIntoTableX] @column_3 = 3, @column_5 = 5; 
相关问题