In any database, it appears to be a common practice to use coalesce() to compare nullable fields for equality. For example, if you’re comparing two nullable string fields, you would use where coalesce(tbl1.stringfield,'') = coalesce(tbl2.stringfield,''). This works because the empty string of '' converts very well contextually to null.
However, what if you’re dealing with datatypes like dates or numbers that don’t have an “empty” equivalent? In Teradata, if you try where coalesce(tbl1.numberfield,'') = coalesce(tbl2.numberfield,''), you get a datatype mismatch error if one of the fields is not null. This is because it tries to compare a number to an empty string. To get it to work, you have to use where coalesce(tbl1.numberfield,0) = coalesce(tbl2.numberfield,0). However, what if tbl1.numberfield is null and tbl2.numberfield actually contains the value of 0? That WHERE condition would return true when, in reality, it should return false since one value is null and the other is 0. The only way around this that I can see is this very clunky case logic:
where case
when
(tbl1.numberfield is null and tbl2.numberfield is null) or
(tbl1.numberfield is not null and tbl2.numberfield is not null) or
tbl1.numberfield <> tbl2.numberfield
then 1
else 0
end = 1
And to think that all this could be avoided if comparing two nulls with a simple equal sign were permitted.
Why not just
This is the standard for checking equity on null-able fields that i am familiar with and it should work in all cases. Its more straight forward for the reader and should run faster.