Why does NULL = NULL evaluate to false in SQL server

前端 未结 19 1565
一向
一向 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:30

    The question:
    Does one unknown equal another unknown?
    (NULL = NULL)
    That question is something no one can answer so it defaults to true or false depending on your ansi_nulls setting.

    However the question:
    Is this unknown variable unknown?
    This question is quite different and can be answered with true.

    nullVariable = null is comparing the values
    nullVariable is null is comparing the state of the variable

提交回复
热议问题