Solved

Use Aggregate in Update Query Access

Posted on 2012-12-27
4
455 Views
Last Modified: 2012-12-27
I am trying to update an invoice total on an invoice table from the lineitem totals on an invoice details table.  I'm finding using an aggregate function within an update query is challenging.

I'm adding these total fields to make it easier for management to gather stats in our small firm.

Here is the SQL that I think should work but it not working and throwing a: "Syntax Error (missing operator) in query expression 't.total from tblPO p inner join..."

UPDATE P
SET p.PO_total = t.total FROM tblPO p 
INNER JOIN
     (SELECT tblPO_Details.PO_ID, SUM(tblPO_Details.subtotal) as total
      FROM tblPO_Details
      GROUP BY tblPO_Details.PO_ID) as t
    ON t.PO_ID = p.PO_ID

Open in new window


Any ideas?
0
Comment
Question by:ClaudeWalker
  • 2
4 Comments
 

Author Comment

by:ClaudeWalker
Comment Utility
I also tried this and it throws "must use updatable query"

UPDATE tblPO 
INNER JOIN
     (SELECT tblPO_Details.PO_ID, SUM(tblPO_Details.subtotal) as total
      FROM tblPO_Details
      GROUP BY tblPO_Details.PO_ID) as t
    ON t.PO_ID = tblPO.PO_ID
SET tblPO.PO_total = t.total 

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
As far as I know, you can't use a subquery in your UPDATE statement like this in Access.

A workaround is to use your aggregate query to make a temporary table (turn it into a make table query) and use that table as the source for your UPDATE.
0
 

Author Closing Comment

by:ClaudeWalker
Comment Utility
That's the only thing that worked :)
0
 
LVL 26

Expert Comment

by:jerryb30
Comment Utility
UPDATE tblPO AS a SET a.po_total = DSum("subtotal","tblPO_Details","po_id = " & [a].[po_id]);
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now