且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么将 SQL 日期变量与 null 进行比较会有这种行为?

更新时间:2023-01-21 11:13:24

简单地说,'NULL' 不等于 'NULL'.NULL"相当于一种不确定状态,其中不确定的事物不一定等于其他事物也不确定.测试空值时使用IS NULL"、ISNULL()"或COALESCE()".将 ANSI_NULLS 设置为 'off' 可以更改此行为,但这不是 ANSI SQL 标准.请参阅 http://msdn.microsoft.com/en-us/library/ms191270.aspx 了解更多信息.

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.