473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help Needed: Aggregating Multiple Columns in MS Access Query

5
I have a table [AAAM] of 15 columns as specified below:

AA100200:Project Code
AAAM140:Staff Code (Individuals' ID #)
AAAM010: Year

Then 12 Columns for each month starting AAAM020 to AAAM130 where the time spent by each individual on the given project in a particular year is entered. I want to aggregate time in all the columns from AAAM020 to AAAM130 grouped by Project Code, Year and Staff Code .

With this (http://www.thescripts.com/forum/thread534172.html) thread in mind , I made two separate queries.

Qury 1 on the Table Named AAAM:
-------------------------------
SELECT dbo_AAAM.AA100200, dbo_AAAM.AAAM010, dbo_AAAM.AAAM140, Sum(dbo_AAAM.AAAM020) AS SumOfAAAM020, Sum(dbo_AAAM.AAAM030) AS SumOfAAAM030, Sum(dbo_AAAM.AAAM040) AS SumOfAAAM040, Sum(dbo_AAAM.AAAM050) AS SumOfAAAM050, Sum(dbo_AAAM.AAAM060) AS SumOfAAAM060, Sum(dbo_AAAM.AAAM070) AS SumOfAAAM070, Sum(dbo_AAAM.AAAM080) AS SumOfAAAM080, Sum(dbo_AAAM.AAAM090) AS SumOfAAAM090, Sum(dbo_AAAM.AAAM100) AS SumOfAAAM100, Sum(dbo_AAAM.AAAM110) AS SumOfAAAM110, Sum(dbo_AAAM.AAAM120) AS SumOfAAAM120, Sum(dbo_AAAM.AAAM130) AS SumOfAAAM130
FROM dbo_AAAM
GROUP BY dbo_AAAM.AA100200, dbo_AAAM.AAAM010, dbo_AAAM.AAAM140;
------------------------------------

Then based upon Query 1, I am running this query:

SELECT Query1.AA100200, Query1.AAAM010, Query1.AAAM140, Sum([SumOfAAAM020]+[SumOfAAAM030]+[SumofAAAM040]+[SumOfAAAM050]+[SumOfAAAM060]+[SumOfAAAM070]+[SumOfAAAM080]+[SumOfAAAM090]+[SumOfAAAM100]+[SumOfAAAM110]+[SumOfAAAM120]+[SumOfAAAM130]) AS Expr1
FROM Query1
GROUP BY Query1.AA100200, Query1.AAAM010, Query1.AAAM140;

But there are no results. Can anyone please guide me as to where is the mistake.

Please help. Thanks.
Jinx
Oct 15 '06 #1
4 4630
jimatqsi
1,271 Expert 1GB
Hi Jinx,
Tell us, does the query1 give any result? Is it only after you run the second query that the results disappear?

What I do whenever I get this sort of thing I start a process of elimination. First I copy by query to a temporary name. Then I start eliminating criteria one at a time until I get some results. Then I look more carefully at the criteria and at the data being tested in that criteria.

If that doesn't lead me to the problem, then I look at my JOIN statements. I'll eliminate one table or another from the JOINs to see what data is delivered under each circumstance. Or I will change the details of the join, change from RIGHT to LEFT, that sort of thing, to see the difference in the results.

Eventually I see and understand the problem.

Jim
Oct 15 '06 #2
Jinx
5
Thanks Jim.

This is what I did. Created a new database with only one table and 15 Columns. Again created two queries and started entering dummy data. And this is my observation:

"With any cell in a column having a 'NULL' value, if you apply the aggregate function of SUM() with two or more columns as the function arguments in a Total Query, Access query simply returns no values. There should either be a zero or some value in each and every cell of the columns of data you are trying to process.

Is it a bug or a deficiency in Access 2003. I don't know.

Anyway, thanks a lot for your time and guidance.
I really appreciate this.

Jinx
Oct 16 '06 #3
jimatqsi
1,271 Expert 1GB
Hi Jinx (I love saying that :)),
Sounds like you need to test for nulls and turn the nulls into zeros before summing. Instead of simplying references the field that comes out of the first query you need to reference it like this:
Expand|Select|Wrap|Line Numbers
  1. SomeName:IIF (IsNull([thefieldname]),0,[thefieldname])
That will return a 0 in SomeName if you have a null, and the value of SomeName if you don't.

Crosstab queries are famous for posing this problem. It got me when I was a little newer than I am now (I'm still kinda new to Access/VB).

Jim

Thanks Jim.

This is what I did. Created a new database with only one table and 15 Columns. Again created two queries and started entering dummy data. And this is my observation:

"With any cell in a column having a 'NULL' value, if you apply the aggregate function of SUM() with two or more columns as the function arguments in a Total Query, Access query simply returns no values. There should either be a zero or some value in each and every cell of the columns of data you are trying to process.

Is it a bug or a deficiency in Access 2003. I don't know.

Anyway, thanks a lot for your time and guidance.
I really appreciate this.

Jinx
Oct 16 '06 #4
Jinx
5
Thank You Jim....Yes this is what I need to do. I have a lot of NULLs in the table and of course I don't want to replace them with ZEROs.

Thanks for the help....I really appreciate this.

J..
Oct 17 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ralph Freshour | last post by:
I'm not sure the follow multiple table query is the right way to do what I need to do although it seems to be working: $php_SQL = "SELECT * ". "FROM basics, personal, photos ". "WHERE...
6
by: JT | last post by:
Hello all, I've been using sql and mysql in particular for several years now, but I'm having some trouble coming up with a query that will pull the data that I need from a mysql table without using...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
4
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class,...
3
by: adtvff | last post by:
Hi, Given a large ascii file (delimited or fixed width) with one ID field and dimensions/measures fields, sorted by dimensions, I'd like to "flatten" or "rollup" the file by creating new...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.