MERGE TARGET T
USING SOURCE S
ON T.ID=S.ID
WHEN MATCHED AND (S.NAME<>T.NAME OR S.DOB<>T.DOB)
THEN UPDATE
SET T.NAME=S.NAME, T.DOB=S.DOB;
The above is not able to handle situation where name/dob is null on source or target side. Because comparisons with NULL return false. How to handle this?
Example:
COALESCE(S.NAME,'')<>COALESCE(T.NAME,'')
Or
COALESCE(S.NAME,0)<>COALESCE(T.NAME,0)
Or
NULLIF(S.NAME,'')<>NULLIF(T.NAME,'')