gogetsome
asked on
one to many update help needed
Hello, I'm attempting to use the following to update a table from another table. This is a one to many update.
When I run this only one row is updated which is not correct.
update a
set a.custnmbr = b.custnmbr
From BB_TNCommFac3_LocationsBSc ott a, cc_scott b
where ltrim(rtrim(b.oldid)) = ltrim(rtrim(a.oldid))
this brings 1149 rows
select * from cc_scott where ltrim(rtrim(oldid)) in (select ltrim(rtrim(oldid)) from BB_TNCommFac3_LocationsBSc ott)
When I run this only one row is updated which is not correct.
update a
set a.custnmbr = b.custnmbr
From BB_TNCommFac3_LocationsBSc
where ltrim(rtrim(b.oldid)) = ltrim(rtrim(a.oldid))
this brings 1149 rows
select * from cc_scott where ltrim(rtrim(oldid)) in (select ltrim(rtrim(oldid)) from BB_TNCommFac3_LocationsBSc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, I need to update the custnmbr on BB_TNCommFac3_LocationsBSc ott with the custnmbr on cc_scott based on the oldid that resides in both tables.
cc_scott is the billing table and BB_TNCommFac3_LocationsBSc ott is the shipping table. There are more shipping address then billing addresses. All shipping addresses need the same custnmbr as their corresponding billing custnmbr.
The cc_scott table has 1149 rows and the BB_TNCommFac3_LocationsBSc ott table has 1909 rows.
cc_scott is the billing table and BB_TNCommFac3_LocationsBSc
The cc_scott table has 1149 rows and the BB_TNCommFac3_LocationsBSc
I typically use this format when updating items based on data from another table:
UPDATE <tblname>
SET <colname> =
SELECT <colname with data for update>
UPDATE <tblname>
SET <colname> =
SELECT <colname with data for update>
Sorry last post was not complete when it uploaded.
typically use this format when updating items based on data from another table:
UPDATE <tblname>
SET <colname> =
SELECT <colname with data for update>
FROM <tablename>
WHERE <conditions>
typically use this format when updating items based on data from another table:
UPDATE <tblname>
SET <colname> =
SELECT <colname with data for update>
FROM <tablename>
WHERE <conditions>
Open in new window