MERGE DestinationTable AS D
USING SourceTable AS S
ON D.Alternate_ID = S.ID
WHEN MATCHED AND
(
D.ID <> S.ID
OR D.col1 <> S.col1
OR D.col2 <> S.col2
OR D.col3 <> S.col3
OR D.col4 <> S.col4
OR D.col5 <> S.col5
OR D.col6 <> S.col6
OR D.col7 <> S.col7
OR D.col8 <> S.col8
)
Hi all, i'am trying to update DestinationTable if any of the column values in SourceTable have changed using the Merge statement snippet above.
However, if i have a NULL value in the destination column and a string or bit value in the source, the comparison D.col8 <> S.col8 will return false because of the way SQL handles comparisons to NULL values. As a result DestinationTable is not updated with new values from SourceTable.
What is the better way to handle this issue. If D.Col8 is NULL and S.Col8 is has a string or bit value, i still want to return true for an expression like D.col8 <> S.col8
SO if i have a value of "Test" in S.Col8 and NULL in D.Col8, I want to update Destination column from NULL to "Test"