In SQL Server 2008, I\'m using MERGE. Everything is fine except that I have 2 nullable columns. If I pass a null value and the target isn\'t null, MERGE doesn\'t see a diffe
Actually, this works better. Just add another substitution value as an OR :-
WHEN MATCHED AND
(
NOT (IsNull(tgt.C, 0) = IsNull(src.C, 0)) OR NOT (IsNull(tgt.C, 1) = IsNull(src.C, 1))
)
THEN ....
WHEN MATCHED AND
(
NULLIF(tgt.C, src.C) IS NOT NULL OR NULLIF(src.C, tgt.C) IS NOT NULL
)
THEN
You can use
WHEN MATCHED AND EXISTS (SELECT tgt.C EXCEPT SELECT src.C)
See this article for more on this issue.