Why does NULL = NULL evaluate to false in SQL server

前端 未结 19 1562
一向
一向 2020-11-22 05:02

In SQL server if you have nullParam=NULL in a where clause, it always evaluates to false. This is counterintuitive and has caused me many errors. I do understa

19条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 05:53

    The equality test, for example, in a case statement when clause, can be changed from

    XYZ = NULL 
    

    to

    XYZ IS NULL
    

    If I want to treat blanks and empty string as equal to NULL I often also use an equality test like:

    (NULLIF(ltrim( XYZ ),'') IS NULL)
    

提交回复
热议问题