locked
Copying Data RRS feed

  • Question

  • I have two databases, each having information about computers.  Each database has the computer serial number.  Database 1 has a purchase date, database 2 does not.  I would like to query database one with the serial number from database two.  When it finds a match, it imports the corresponding purchase date to database two.  How do I accomplish this?
    Wednesday, June 7, 2017 6:43 PM

All replies

  • Hi brodiemac,

    Are both of databases in the same instance? If so, You could use MERGE statement and here is a query example:

    Merge into DatabaseTwo.TableSchemaA.TableA AS A using DatabaseOne.TableSchemaB.TableB AS B
    on A.SerialNumber=B.SerialNumber
    when matched then update set B.PurchaseDate=A.PurchaseDate

    If you want to synchronize data from remote table, you could use OPENQUERY and refer to this thread. By the way could you please provide more details about the definition for you tables and schema?

    For more information, please refer to this blog.

    Hope it can be helpful
    Regards,
    Davy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, June 8, 2017 5:12 AM
  • Hi brodiemac,

    Was your issue resolved? If so, please mark the corresponding replies as answer so it could be helpful to others who have similar issues. If not, please provide more details about this issue.

    Regards,
    Davy

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 16, 2017 2:44 AM