在测试是否传递了存储过程的可选参数时,我真的更愿意不依赖于0
,-1
或NULL
之类的标记值。有没有确定的方法来检查?
例如,我可以检查是否在调用中指定了这些样本参数中的任何参数而不假设它们不以特定值传递?
CREATE PROCEDURE TestProcedure
@SampleStringParam VARCHAR(MAX) = NULL
,@SampleBooleanParam BIT = 0
,@MultiplicativeIdentity REAL = 1
,@MultiplicativeInverse REAL = -1
,@AdditiveIdentity REAL = 0
AS
...
答案 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