Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9105701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:09:59+00:00 2026-06-17T02:09:59+00:00

I have source and table destination tables like this Source: Column1 Column2 Column3 Column4

  • 0

I have source and table destination tables like this

Source:

    Column1 Column2 Column3 Column4

Destination:

    Column1 Column2 Column5 Column6

How can I implement this logic in SQL SERVER

IF SOURCE.Column1 = DESTINATION.Column1 AND SOURCE.Column2 = DESTINATION.Column2
UPDATE DESTINATION Column5 = SOURCE.Column1 + 12 (some other logic)
ELSE
Do something else

The issue is, that I have to deal with billion rows, so what is the best way to implement the above logic

EDIT1

IF SOURCE.Column1 = DESTINATION.Column1 AND SOURCE.Column2 = DESTINATION.Column2
UPDATE DESTINATION Column5 = SOURCE.Column1 + 12 (some other logic)
ELSE
**INSERT SOURCE table row to the destination**

How can I implement the same with merge statement, because I have to consider only two columns

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:10:00+00:00Added an answer on June 17, 2026 at 2:10 am


    You can UPDATE with JOIN and that would be more performance wise in your case. Like so:

    UPDATE d
    SET d.Column5 = CASE WHEN some logic THEN s.Column1 + 12 (some other logic)
                         ELSE Something else
                    ELSE
    FROM DESTINATION d
    LEFT JOIN SOURCE s ON s.Column2 = d.Colcumn2;
    


    You can use the MERGE statement like so:

    MERGE INTO SOURCE AS TGT
    USING DESTINATION AS SRC
      ON TGT.Column1 = SRC.Column1 
    WHEN MATCHED THEN
      UPDATE SET
        TGT.Column5 = SRC.Column1 + 12 (some other logic)
    WHEN NOT MATCHED THEN
      INSERT (Source columns list)
      VALUES (...);
    

    Note that:

    • In the INSERT statement there was no INTO TableName, because the name of the target table is already defined in the MERGE clause, which is SOURCE. Thats why I defined SOURCE AS TGT and DESTINATION AS SRC.

    • It is mandatory to end the MERGE statement with semicolon. And it is best practice to do so with al sql statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3 tables that look like this: (source: InsomniacGeek.com ) On the
I have two identical SQL Server tables ( SOURCE and DESTINATION ) with lots
I have the following HTML table code: <table> <tr> <th>Time</th> <th>Source</th> <th class=hide-on-phones>Destination</th> <th>Duration</th>
I have two tables a source and a destination. I want to flag the
I have two columns, source and destination in table Hyperlink, to store the source
I have a form with a table source, the form has a few fields
I have a Data Class called MyTable, and the source property is TABLE (table
I have a database with several hundred tables imported from a third source. Using
Need some help with a query.. I have three tables. Source id name 1
I have a merge statement DESTINMATION TABLE =~ DST SOURCE TABLE =~ SRC MERGE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.