netadmin2004
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?
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?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.