[英]Is querying for IS NULL necessary in this CASE expression?
I've got this case statement: 我有以下案例说明:
CASE
WHEN SecondScriptKind_ID IS NULL THEN 0
WHEN SecondScriptKind_ID IN (@SqlQuery, @SqlScript) THEN 1
ELSE 0
END
Is the WHEN SecondScriptKind_ID IS NULL
necessary in this case? 在这种情况下,是否需要WHEN SecondScriptKind_ID IS NULL
?
Both @SqlQuery and @SqlScript are guaranteed to contain values (NOT NULL). 保证@SqlQuery和@SqlScript都包含值(NOT NULL)。
When ANSI_NULLS
is set on
, it is not necessary: even if @SqlQuery
or @SqlScript
happen to be NULL
, the IN
is not going to match a NULL
SecondScriptKind_ID
to that list. 将ANSI_NULLS
设置为on
,则没有必要:即使@SqlQuery
或@SqlScript
碰巧为NULL
, IN
也不SecondScriptKind_ID
NULL
SecondScriptKind_ID
匹配到该列表。 In other words, the condition 换句话说,条件
NULL IN (NULL, 123)
evaluates to NULL
. 评估为NULL
。 The only reason to keep an explicit NULL
check there would be if you wanted to return a different number for NULL
, say, a negative 1. 保留显式NULL
检查的唯一原因是,如果您想为NULL
返回一个不同的数字,例如负1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.