SQL Server 2022 introduced the IS [NOT] DISTINCT FROM
predicate that compares the equality of two expressions and guarantees a true or false result, even if one or both operands are NULL
.
Normally if we compare two NULL values, they will always be different (although this will depend on your ANSI_NULLS
setting – setting ANSI_NULLS
to OFF
will result in NULL
s being treated as equal). The IS [NOT] DISTINCT FROM
predicate enables us to compare NULL
s as though they’re equal, even when our ANSI_NULLS
setting is set to ON
.