Consultor Eletrônico



Kbase P186445: How to update columns from one table using data from another?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   22/04/2011
Status: Unverified

GOAL:

How to update columns from one table using data from another?

GOAL:

How to UPDATE certain records from a table using data from related records in another table of the same database?

GOAL:

How to copy values from table A to table B in the same database?

GOAL:

What is the syntax of the SQL UPDATE statement to update field values from one table to another?

FACT(s) (Environment):

All Supported Operating Systems
OpenEdge Category: SQL
OpenEdge 10.2A
OpenEdge 10.2B

FIX:

Following is the syntax to UPDATE the Balance field of the Customer table from the Balance field of another table myCustomer. The WHERE clause ensures that only rows updated in the Customer table are those that have related fields in myCustomer:

UPDATE PUB.Customer
SET (Balance) = (SELECT myCustomer.Balance FROM PUB.myCustomer WHERE myCustomer.Custnum = Customer.Custnum)
WHERE PUB.Customer.Custnum IN (SELECT Custnum FROM PUB.myCustomer)