anconley
anconley

Reputation: 1

How to Update a table while joining another table

I know how to join these two tables (invoices and payables). Payables has a balancedue column and I need to make that the same as Invoices.originalamount.

What I have written is:

update payables p
set p.balancedue= i.originalamount
From payables p
join invoices i on p.id=i.id
where nationalaccountcode='xxx'

But i'm getting an error. Any help? SSMS 2012, if that helps.

Upvotes: 0

Views: 34

Answers (1)

user2989408
user2989408

Reputation: 3137

Try this...

UPDATE Payables 
    SET balancedue = i.originalamount
FROM invoices i
WHERE nationalaccountcode='xxx' AND Payables.id = i.id

Upvotes: 1

Related Questions