Connecting Tech Pros Worldwide Forums | Help | Site Map

Using Sum in a Totals Query

Newbie
 
Join Date: Aug 2007
Posts: 4
#1: Aug 22 '07
I know this is a stupid question but...

I'm trying to total some columns in a query using sum. I'm not getting any results, what am I not seeing?

And my apologies, I'm new to access.

JKing's Avatar
Moderator
 
Join Date: Jun 2007
Location: Niagara Falls, Ontario
Posts: 557
#2: Aug 22 '07

re: Using Sum in a Totals Query


Could you post the SQL for your query. It would be help in figuring out where the error is.

Also perhaps explain briefly the data you are working with and what result you wish to produce from the query so not only can we spot the error but ensure you get the proper results.
Newbie
 
Join Date: Aug 2007
Posts: 4
#3: Aug 22 '07

re: Using Sum in a Totals Query


Quote:

Originally Posted by JKing

Could you post the SQL for your query. It would be help in figuring out where the error is.

Also perhaps explain briefly the data you are working with and what result you wish to produce from the query so not only can we spot the error but ensure you get the proper results.

I'm just tracking donations by Name and category(numeric) for a nonprofit org..Here's the sql:
Expand|Select|Wrap|Line Numbers
  1. SELECT MEF2008.[Last Name], MEF2008.[First Name], Sum(MEF2008.[MEF 2008]) AS [SumOfMEF 2008], Sum(MEF2008.[PTC 2008]) AS [SumOfPTC 2008], Sum(MEF2008.[Booster 2008]) AS [SumOfBooster 2008], Sum(MEF2008.[B-Lights 2008]) AS [SumOfB-Lights 2008], Sum(MEF2008.[B-Cards 2008]) AS [SumOfB-Cards 2008], Sum(MEF2008.[Proj Grad 2008]) AS [SumOfProj Grad 2008], Sum(MEF2008.[Snr Bkfst 2008]) AS [SumOfSnr Bkfst 2008], Sum(MEF2008.[WBB 2008]) AS [SumOfWBB 2008], Sum(MEF2008.[IB 2008]) AS [SumOfIB 2008], Sum(MEF2008.[TWL 2008]) AS [SumOfTWL 2008], Sum(MEF2008.[TA 2008]) AS [SumOfTA 2008], Sum(MEF2008.[CB 2008]) AS [SumOfCB 2008], Sum(MEF2008.[SFA 2008]) AS [SumOfSFA 2008], Sum(MEF2008.[ST 2008]) AS [SumOfST 2008], Sum(MEF2008.[MB 2008]) AS [SumOfMB 2008], Sum(MEF2008.[Drama 2008]) AS [SumOfDrama 2008], Sum(MEF2008.[A-A-B  2008]) AS [SumOfA-A-B  2008], Sum(MEF2008.[HR 2008]) AS [SumOfHR 2008], Sum(MEF2008.[Art 2008]) AS [SumOfArt 2008], Sum(MEF2008.[MEM 2008]) AS [SumOfMEM 2008], Sum(MEF2008.[PF 2008]) AS [SumOfPF 2008]
  2. FROM MEF2008
  3. GROUP BY MEF2008.[Last Name], MEF2008.[First Name]
  4. OR (((Sum(MEF2008.[PTC 2008]))>(0))) OR (((Sum(MEF2008.[Booster 2008]))>(0))) OR (((Sum(MEF2008.[B-Lights 2008]))>(0))) OR (((Sum(MEF2008.[B-Cards 2008]))>(0))) OR (((Sum(MEF2008.[Proj Grad 2008]))>(0))) OR (((Sum(MEF2008.[Snr Bkfst 2008]))>(0))) OR (((Sum(MEF2008.[WBB 2008]))>(0))) OR (((Sum(MEF2008.[IB 2008]))>(0))) OR (((Sum(MEF2008.[TWL 2008]))>(0))) OR (((Sum(MEF2008.[TA 2008]))>(0))) OR (((Sum(MEF2008.[CB 2008]))>(0))) OR (((Sum(MEF2008.[SFA 2008]))>(0))) OR (((Sum(MEF2008.[ST 2008]))>(0))) OR (((Sum(MEF2008.[MB 2008]))>(0))) OR (((Sum(MEF2008.[Drama 2008]))>(0))) OR (((Sum(MEF2008.[A-A-B  2008]))>(0))) OR (((Sum(MEF2008.[HR 2008]))>(0))) OR (((Sum(MEF2008.[Art 2008]))>(0))) OR (((Sum(MEF2008.[MEM 2008]))>(0))) OR (((Sum(MEF2008.[PF 2008]))>(0)));
  5.  
JKing's Avatar
Moderator
 
Join Date: Jun 2007
Location: Niagara Falls, Ontario
Posts: 557
#4: Aug 23 '07

re: Using Sum in a Totals Query


I think the problem is in your GROUP BY clause. I really don't understand the use of ORs in there. What is you're trying to accomplish there?
Newbie
 
Join Date: Aug 2007
Posts: 4
#5: Aug 23 '07

re: Using Sum in a Totals Query


I copied the query from one showing individual donors, not wanting to show zero dollar contributions. It shouldn't make any difference though? What do you mean the problem is in my group by settings?
JKing's Avatar
Moderator
 
Join Date: Jun 2007
Location: Niagara Falls, Ontario
Posts: 557
#6: Aug 23 '07

re: Using Sum in a Totals Query


I think you want something closer to this:

Expand|Select|Wrap|Line Numbers
  1. SELECT MEF2008.[Last Name], MEF2008.[First Name], Sum(MEF2008.[MEF 2008]) AS [SumOfMEF 2008], Sum(MEF2008.[PTC 2008]) AS [SumOfPTC 2008], Sum(MEF2008.[Booster 2008]) AS [SumOfBooster 2008], Sum(MEF2008.[B-Lights 2008]) AS [SumOfB-Lights 2008], Sum(MEF2008.[B-Cards 2008]) AS [SumOfB-Cards 2008], Sum(MEF2008.[Proj Grad 2008]) AS [SumOfProj Grad 2008], Sum(MEF2008.[Snr Bkfst 2008]) AS [SumOfSnr Bkfst 2008], Sum(MEF2008.[WBB 2008]) AS [SumOfWBB 2008], Sum(MEF2008.[IB 2008]) AS [SumOfIB 2008], Sum(MEF2008.[TWL 2008]) AS [SumOfTWL 2008], Sum(MEF2008.[TA 2008]) AS [SumOfTA 2008], Sum(MEF2008.[CB 2008]) AS [SumOfCB 2008], Sum(MEF2008.[SFA 2008]) AS [SumOfSFA 2008], Sum(MEF2008.[ST 2008]) AS [SumOfST 2008], Sum(MEF2008.[MB 2008]) AS [SumOfMB 2008], Sum(MEF2008.[Drama 2008]) AS [SumOfDrama 2008], Sum(MEF2008.[A-A-B  2008]) AS [SumOfA-A-B  2008], Sum(MEF2008.[HR 2008]) AS [SumOfHR 2008], Sum(MEF2008.[Art 2008]) AS [SumOfArt 2008], Sum(MEF2008.[MEM 2008]) AS [SumOfMEM 2008], Sum(MEF2008.[PF 2008]) AS [SumOfPF 2008]
  2. FROM MEF2008
  3. WHERE (((Sum(MEF2008.[PTC 2008]))>(0))) OR (((Sum(MEF2008.[Booster 2008]))>(0))) OR (((Sum(MEF2008.[B-Lights 2008]))>(0))) OR (((Sum(MEF2008.[B-Cards 2008]))>(0))) OR (((Sum(MEF2008.[Proj Grad 2008]))>(0))) OR (((Sum(MEF2008.[Snr Bkfst 2008]))>(0))) OR (((Sum(MEF2008.[WBB 2008]))>(0))) OR (((Sum(MEF2008.[IB 2008]))>(0))) OR (((Sum(MEF2008.[TWL 2008]))>(0))) OR (((Sum(MEF2008.[TA 2008]))>(0))) OR (((Sum(MEF2008.[CB 2008]))>(0))) OR (((Sum(MEF2008.[SFA 2008]))>(0))) OR (((Sum(MEF2008.[ST 2008]))>(0))) OR (((Sum(MEF2008.[MB 2008]))>(0))) OR (((Sum(MEF2008.[Drama 2008]))>(0))) OR (((Sum(MEF2008.[A-A-B  2008]))>(0))) OR (((Sum(MEF2008.[HR 2008]))>(0))) OR (((Sum(MEF2008.[Art 2008]))>(0))) OR (((Sum(MEF2008.[MEM 2008]))>(0))) OR (((Sum(MEF2008.[PF 2008]))>(0)))
  4. GROUP BY MEF2008.[Last Name], MEF2008.[First Name]
  5. ;
  6.  
Newbie
 
Join Date: Aug 2007
Posts: 4
#7: Aug 23 '07

re: Using Sum in a Totals Query


Thanks, I removed the group by fields and that got me close. Any idea whats the best way to total columns on detailed records as you would in excel though?
Reply