Why does comparing a SQL date variable to null behave in this way?

前端 未结 2 1955
情歌与酒
情歌与酒 2020-12-07 02:10

I just came across an interesting problem with a procedure I am writing in SQL.

In my proc I have 2 dates, which are optional params defaulted to NULL, I want to che

2条回答
  •  囚心锁ツ
    2020-12-07 02:42

    Care must be taken when comparing null values. The behavior of the comparison depends on the setting of the SET ANSI_NULLS option.

    When SET ANSI_NULLS is ON, a comparison in which one or more of the expressions is NULL does not yield either TRUE or FALSE; it yields UNKNOWN. This is because a value that is unknown cannot be compared logically against any other value. This occurs if either an expression is compared to the literal NULL, or if two expressions are compared and one of them evaluates to NULL.

    See NULL Comparison Search Conditions

提交回复
热议问题