Avatar of netadmin2004
netadmin2004
Flag for United States of America asked on

Update a number of records using a select top statement

Hi guys,

I need 2 things.

First I have a table where I need to grab around 2000 records from the account table that are assigned to a certain rep and reassign them.

My thoughts (though wrong) are somthing like this:
UPDATE    ACCOUNT
SET              ACCOUNTMANAGERID = 'U6UJ9A000016'
WHERE     (SELECT TOP 2000 ACCOUNTMANAGERID
                       FROM          ACCOUNT
                       WHERE      (ACCOUNTMANAGERID = 'U6UJ9A000020'))

Second, I need to now assign the records I just reassigned and update the contact table to reflect those changes.

So I'm guessing something like the following:?
UPDATE    c
SET              accountmanagerid = 'U6UJ9A000016'
FROM         Contact c JOIN
                      Account a ON c.AccountID = a.AccountID AND a.accountmanager = 'U6UJ9A000016'

Any thoughts?
Databases

Avatar of undefined
Last Comment
andygarratt

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
andygarratt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck