SQL 1999 and later include the <distinct predicate> IS [NOT] DISTINCT FROM.The definition of distinct is (quoting from the 2003 standard) "informally, not equal, not both null." This is consistent with where SQL Server (following the standard) already uses the keyword DISTINCT. Adding <distinct predicate> to T-SQL would simplify coding of joins, in particular, and as of 2008, MERGE statements in a variety of typical scenarios.Example:SELECT T1.this, T2.thatFROM T1 JOIN T2ON T1.entry IS NOT DISTINCT FROM T2.entryCurrently, this must be written asSELECT T1.this, T2.thatFROM T1 JOIN T2ON ( T1.entry = T2.entry OR (T1.entry IS NULL AND T2.entry IS NULL))This is a common requirement, but coding this for many columns is both tedious and error-prone (especially because of AND/OR precedence issues). Changing the setting of ANSI_NULLS is not a solution, because it does not affect column-to-column comparisons, only column to variable comparisons. Setting ANSI_NULLS to off is also non-standard and not granular enough to apply to specific comparisons in a single query.
Category