How to compare values which may both be null in T-SQL

后端 未结 14 1743
情书的邮戳
情书的邮戳 2020-12-23 14:20

I want to make sure I\'m not inserting a duplicate row into my table (e.g. only primary key different). All my fields allow NULLS as I\'ve decided null to mean \"all values

14条回答
  •  春和景丽
    2020-12-23 14:53

    Along the same lines as @Eric's answer, but without using a 'NULL' symbol.

    (Field1 = Field2) OR (ISNULL(Field1, Field2) IS NULL)
    

    This will be true only if both values are non-NULL, and equal each other, or both values are NULL

提交回复
热议问题