UPDATE from Database 1 to Database 2

  • Hi. I need to update values in database 2 table A from database 1 table A.

    My query executes and says 845 rows affected but now values are written?

    I run from the database I want to update to (db2).

    Query as follows:

    UPDATE Suppliers

    SET

    Suppliers.Bank = [DB1].[dbo].[Suppliers].Bank,

    Suppliers.Account = [DB1].[dbo].[Suppliers].Account

    FROM [DB1].[dbo].[Suppliers]

    WHERE SupplierId = SupplierId

    Where am I going wrong?

    Many Thanks,

    Phil.

    -------------------------------------------------------------------------------------
    A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

    Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

    Tommy Cooper

  • Hi

    Are you sure that the posted statement works?

    Maybe try this:

    UPDATE sp1 SET

    sp1.Bank = sp2.Bank,

    sp1.Account = sp2.Account

    FROM [DB1].[dbo].[Suppliers] sp1

    JOIN [Training].[dbo].[Suppliers] sp2 ON sp1.SupplierId = sp2.SupplierId

    Greets

    Flo

  • Thanks that worked a treat.

    Kind Regards,

    Phil.

    -------------------------------------------------------------------------------------
    A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

    Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

    Tommy Cooper

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

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