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

前端 未结 2 1965
情歌与酒
情歌与酒 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条回答
  •  Happy的楠姐
    2020-12-07 03:05

    Simply put 'NULL' does not equal 'NULL'. 'NULL' is comparable to a state of uncertainty, where one thing being uncertain does not necessarily equal something else that is also uncertain. Use 'IS NULL', 'ISNULL()', or 'COALESCE()' when testing for nulls. Setting ANSI_NULLS to 'off' can change this behavior, but it is not the ANSI SQL standard. See http://msdn.microsoft.com/en-us/library/ms191270.aspx for more info.

提交回复
热议问题