Bart
Bart

Reputation: 565

Update table based on value inside this table

I'm trying to update a tablecolumn based on another value inside this table but I keep getting an error.

My query is as follows:

    UPDATE partcreditor 
    SET partcreditor.creditorid = creditor.creditorid
    FROM partcreditor
    INNER JOIN creditor ON partcreditor.creditornr = creditor.creditornr
    WHERE creditor.relgroupid = 1
    AND creditor.creditortypeid = 1

Upvotes: 2

Views: 46

Answers (1)

Arulkumar
Arulkumar

Reputation: 13237

UPDATE partcreditor AS PC
INNER JOIN creditor AS CR ON PC.creditornr = CR.creditornr
SET PC.creditorid = CR.creditorid
WHERE CR.relgroupid = 1 AND CR.creditortypeid = 1

No need to use the FROM clause in the update. As well as use alias name for better readability.

Upvotes: 2

Related Questions