0
votes

I have following SQL UPDATE query:

UPDATE Invoices
SET Price = (SELECT SUM(Price*ProductsAndServices.Amount) FROM InvoicesItems 
  LEFT JOIN ProductsAndServices ON ProductsAndServices.ProductsAndServicesID = InvoicesItems.ProductsAndServicesID 
WHERE Invoices.InvoicesID = InvoicesItems.InvoicesID)

I have following TABLES | Columns (i am providing only the important-ones):

Invoices            | (InvoicesID, Price) 
InvoicesItems       | (InvoicesItemsID,InvoicesID,ProductsAndServicesID,Amount)
ProductsAndServices | (ProductsAndServicesID, Price)

I want to create query that takes all the products from ProductsAndServices for invoice. Multiply it by amount (this column is for amount of this Product), And than update the final invoice price.

Can you please tell me, how to do it?

  1. If i removed "* ProductsAndServices.Amount" It said the error that is in title..."
  2. When i leave there this Amount multiplying, it prompts for value of ProductsAndServices.Amount

Thanks a lot

1

1 Answers

0
votes

You use Price to identify a field, but because there is a column with that name in 2 tables Access doesn't know which one you want to use, so you need to tell it.

For example; SUM(ProductsAndServices.Price * ProductsAndServices.Amount)