Use of merge under Match Found condition

  • I have a source and target table. target table is being updating weekly. Using Merge when match is found, i only want to update those columns where value is changed rather than updating every column. How it can be done?

    Any help will be helpful.

  • Are you merging or you're just updating? If you're just updating, use UPDATE.

    Here are some general examples:

    UPDATE t

    SET value = s.value

    FROM TargetTable t

    JOIN SourceTable s ON t.id = s.id

    AND t.value <> s.value;

    MERGE INTO TargetTable t

    USING (SELECT id, value FROM SourceTable) AS s

    ON t.id = s.id

    WHEN MATCHED AND t.value <> s.value

    UPDATE SET value = s.value;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Is this helpful?

    tablediff Utility

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply