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 8661863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:36:03+00:00 2026-06-12T16:36:03+00:00

Assume there are two tables: Remote_table and My_table . Remote_table has 6 columns: PROJECT

  • 0

Assume there are two tables: Remote_table and My_table.

Remote_table has 6 columns:

PROJECT   JOB_TYPE   MONTH  YEAR**       HOURS     IS_DELETED
134393     70         1       2013      30     0
134393     70         2       2013      50     0
134393     70         3       2013      80     0
134393     70         10      2012      10     0
134393     70         11      2012      0      0
134393     70         12      2012      15     0

My_table is a copy of remote_table.

I tried to copy only the new records from the remote_table by this query:

SELECT    *
FROM [remote_DB].[LudanProjectManager].[dbo].Remote_table            
EXCEPT           
SELECT    *
FROM My_table

It works OK but I get a duplicate primary key exception when changes have been made on the remote_table on the hours column.

Can anyone think of a way to copy only the new records from remote_table and if changes has been made on old records, to identify them and update the my_table to correspond?

  • 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-12T16:36:04+00:00Added an answer on June 12, 2026 at 4:36 pm

    Since you are using SQL Server 2008, you can use MERGE :

    MERGE INTO My_table AS TGT
    USING Remote_table AS SRC
      ON TGT.PROJECT = SRC.PROJECT, -- This is the matching condition. 
         TGT.YEAR    = SRC.YEAR,
       ---
    WHEN NOT MATCHED THEN
      INSERT(PROJECT, JOB_TYPE, MONTH, YEAR, HOURS, IS_DELETED)
      VALUES(SRC.PROJECT, SRC.JOB_TYPE, SRC.MONTH, SRC.YEAR, SRC.HOURS,
             SRC.IS_DELETED);
    

    Note that:

    • The matched and unmatched rows are determined based on the coditions specified in the ON clause, may be you need to restrict the matching rows using extra conditions , TGT.Year = SRC.TGT, .. or just matched on the PROJECT field only using ON TGT.PROJECT = SRC.PROJECT.
    • You have to end the MEREGE statement with a semicolon. It is mandatory.
    • In the INSERT statement there was no INTO TableName because the name of the target table is already defined in the MERGE clause.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two tables with identical structure. Let's assume the number of rows in
Assume that we have two tables: Roles and Reports . And there exists a
I need to synchronize two tables. Let's assume that the tables contain following columns:
Assume there are two separate web applications: a sports site with admin backend an
Assume there is a TFS project Project with the subfolders trunk and 1.0 .
Let's assume I have a database with two tables: categories and articles . Every
Let's assume the next two tables: users (username, region, location, department, subdepartment) and structure
I have two tables say ( FCT_SALES_SUMMARY_A and FCT_SALES_SUMMARY_B ). If we assume that
I have two tables, users{name,id,age_range_id} and age_ranges{id,range_name} . There are also two models, controllers
For example, say I have two tables, Product and Order . Product has ID

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.