检查可选参数是否已传递给存储过程

时间:2017-10-23 19:35:49

标签: sql sql-server tsql

在测试是否传递了存储过程的可选参数时,我真的更愿意不依赖于0-1NULL之类的标记值。有没有确定的方法来检查?

例如,我可以检查是否在调用中指定了这些样本参数中的任何参数而不假设它们以特定值传递?

CREATE PROCEDURE TestProcedure
     @SampleStringParam VARCHAR(MAX) = NULL
    ,@SampleBooleanParam BIT = 0
    ,@MultiplicativeIdentity REAL = 1
    ,@MultiplicativeInverse REAL = -1
    ,@AdditiveIdentity REAL = 0
AS
...

1 个答案:

答案 0 :(得分:1)

CREATE PROCEDURE TestProcedure
     @SampleStringParam VARCHAR(MAX) = NULL
    ,@SampleBooleanParam BIT = NULL
    ,@MultiplicativeIdentity REAL = NULL
    ,@MultiplicativeInverse REAL = NULL
    ,@AdditiveIdentity REAL = NULL
AS
IF @SampleBooleanParam IS NULL
--  @SampleBooleanParam DEFAULT
SET @SampleBooleanParam = 0