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.
jacobJLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lcohanDatabase AnalystCommented:
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?
0
lcohanDatabase AnalystCommented:
--assuming this "where server2.weis2 .[dbo].[ITEM_MASTER].upc=null"
--will reduce a lot the server2 recordset
use weis2
go
create view v_items2join as
select upc from [dbo].[ITEM_MASTER]
where [dbo].[ITEM_MASTER].upc=null
go

--on Server1:
update server1.weis1.[dbo].[CAT_RootOrg]
      set CAT_RootOrg.SKUCode=999999
from server1.weis1.[dbo].[CAT_RootOrg] t1
      inner join server2.weis2.[dbo].v_items2join t2 on t1.upc = t2.upc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jacobJLAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.