NULL values are excluded. Why?

前端 未结 4 1858
谎友^
谎友^ 2020-12-16 11:47

This is about a bizarre behaviour I found in Microsoft Sql Server. Please correct me if I\'m wrong.

SELECT COUNT(*) FROM TABLEA 
WHERE [Column1] IS NULL;
         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 12:08

    This is actually a common mistake made with SQL Server in treating NULL as a value. By default, it's treated as UNKNOWN, as documented here. So, in your view, you also need to include an OR t1.[Column1] IS NULL.

    You can change this behavior by calling SET ANSI_NULLS OFF. It is not recommended to use this, however, as the feature is deprecated as pointed out by @Martin Smith.

    This is not a SQL Server specific issue, however. It's part of the ANSI SQL standard.

提交回复
热议问题