Solved

Access Update query syntax

Posted on 2014-04-02
5
362 Views
Last Modified: 2014-04-03
Good Afternoon Guru's,

I am having an issue with an update query in ms access.

table structure:
                                         month1  month2   month3   month4  etc.......
grp1   money                        5.00       6.23        52.3         54.21
grp1   something
grp1   something1
grp1   average
grp2   money                        5.36        8.21        4.14          5.98
grp2   something
grp2   something1
grp2   average

Issue: We need to update each grp's 'average' line for each month based on the sum of all values in each respective grps 'money' line.
This is what is created so far, and I am running into syntax issues:

UPDATE ChartDBSource_Template
SET ChartDBSource_Template.Mar = ([ChartDBSource_Budget].[Mar] + [ChartDBSource_Budget].[Jan] + ([ChartDBSource_Budget].[Feb] + ([ChartDBSource_Budget].[Mar] + ([ChartDBSource_Budget].[Apr] + ([ChartDBSource_Budget].[May] + ([ChartDBSource_Budget].[Jun] + ([ChartDBSource_Budget].[Jul] + ([ChartDBSource_Budget].[Aug] + ([ChartDBSource_Budget].[Sep] + ([ChartDBSource_Budget].[Oct] + ([ChartDBSource_Budget].[Nov] + ([ChartDBSource_Budget].[Dec] / 12)
WHERE ChartDBSource_Template.CHART_BIN like 'BudAvg';
0
Comment
Question by:UserName935
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 39973062
Your parentheses were off. The Nz is a IfNull function. Try this:

UPDATE ChartDBSource_Template
SET ChartDBSource_Template.Mar = ((Nz([ChartDBSource_Budget].[Mar],0) +
                                  Nz([ChartDBSource_Budget].[Jan],0) +
                                  Nz([ChartDBSource_Budget].[Feb],0) +
                                  Nz([ChartDBSource_Budget].[Mar],0) +
                                  Nz([ChartDBSource_Budget].[Apr],0) +
                                  Nz([ChartDBSource_Budget].[May],0) +
                                  Nz([ChartDBSource_Budget].[Jun],0) +
                                  Nz([ChartDBSource_Budget].[Jul],0) +
                                  Nz([ChartDBSource_Budget].[Aug],0) +
                                  Nz([ChartDBSource_Budget].[Sep],0) +
                                  Nz([ChartDBSource_Budget].[Oct],0) +
                                  Nz([ChartDBSource_Budget].[Nov],0) +
                                  Nz([ChartDBSource_Budget].[Dec],0) )/ 12)
WHERE ChartDBSource_Template.CHART_BIN like 'BudAvg';

Open in new window

0
 

Author Closing Comment

by:UserName935
ID: 39973363
Thank you very much !!!!
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39973409
UserName935,

Thank you for accepting my answer. For future reference you may want to look at the grading standards for EE.
0
 

Author Comment

by:UserName935
ID: 39974958
I apologize if I failed on the grading task.  

If it is possible, feel free to change it to what it is you desire, and, thank you again for the assistance.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

762 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

18 Experts available now in Live!

Get 1:1 Help Now