Link to home
Start Free TrialLog in
Avatar of Jacob L
Jacob LFlag for United States of America

asked on

Updating data in a remote table by using a linked server

Hi,
I am trying to update a column in one database from a select statement on another database.
lets call database1 = weis1 and is on server1
and database2 = weis2 and is on server2


EXEC sp_addlinkedsrvlogin 'Accounts', 'true'

update server1.weis1 .[dbo].[CAT_RootOrg]
      set CAT_RootOrg.SKUCode=999999
      From server1.weis1.[dbo].[CAT_RootOrg] t1
            join server2.weis2 .[dbo].[ITEM_MASTER] t2
                  on t1.upc = t2.upc
         where server2.weis2 .[dbo].[ITEM_MASTER].upc=null

Sorry i am just a novice at best when comes to sql. Any help on this would be great.
Avatar of lcohan
lcohan
Flag of Canada image

Are you getting any error or what is the issue? The only problem I see assuming the user running it has all necessary rights in place is that it will be very slow on large volumes. Can you create a view on Server2 and filter that data at least right at the source?
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jacob L

ASKER

Thanks icohan. The problem is more of permissions thing. My DBA will have to run it. but your query above helps a lot. Thanks so much