Why does NULL = NULL evaluate to false in SQL server

前端 未结 19 1887
一向
一向 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条回答
  •  萌比男神i
    2020-11-22 05:46

    null is unknown in sql so we cant expect two unknowns to be same.

    However you can get that behavior by setting ANSI_NULLS to Off(its On by Default) You will be able to use = operator for nulls

    SET ANSI_NULLS off
    if null=null
    print 1
    else 
    print 2
    set ansi_nulls on
    if null=null
    print 1
    else 
    print 2
    

提交回复
热议问题