Connecting Tech Pros Worldwide Forums | Help | Site Map

SUM & Count

Newbie
 
Join Date: Jan 2008
Posts: 19
#1: Jan 8 '08
Hi,

I am trying to perform a calculation that adds together two 'Counts' (on seperate tables) to give a total value.

The code for the two counts is:

Count(Tbl_Contract_Maintenance.[Supplier ID]) AS [No of General Contracts], Count(Tbl_Contract_General_Head.[Supplier ID]) AS [No of Maintenance Contracts]

I thought that i might have been able to use the 'Sum' Function in an expression like sum(count(Tbl_Contract_Maintenance.[Supplier ID]))+count(Tbl_Contract_General_Head.[Supplier ID]).....

but this is not working.

is there another way around this?

Thanks

JKing's Avatar
Moderator
 
Join Date: Jun 2007
Location: Niagara Falls, Ontario
Posts: 557
#2: Jan 8 '08

re: SUM & Count


Quote:

Originally Posted by jadeverell

Hi,

I am trying to perform a calculation that adds together two 'Counts' (on seperate tables) to give a total value.

The code for the two counts is:

Count(Tbl_Contract_Maintenance.[Supplier ID]) AS [No of General Contracts], Count(Tbl_Contract_General_Head.[Supplier ID]) AS [No of Maintenance Contracts]

I thought that i might have been able to use the 'Sum' Function in an expression like sum(count(Tbl_Contract_Maintenance.[Supplier ID]))+count(Tbl_Contract_General_Head.[Supplier ID]).....

but this is not working.

is there another way around this?

Thanks

Hey there,

Have you tried making a separate query for each count and then combining those fields in a new query?
JKing's Avatar
Moderator
 
Join Date: Jun 2007
Location: Niagara Falls, Ontario
Posts: 557
#3: Jan 8 '08

re: SUM & Count


Here's an example:

qselGeneralContracts: Query of General Contracts
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(Tbl_Contract_General_Head.[Supplier ID]) AS [No of General Contracts]
  2. FROM
  3.  
qselMaintenanceContracts: Query of Maintenance Contracts
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(Tbl_Contract_Maintenance.[Supplier ID]) AS [No of Maintenance Contracts]
  2. FROM Tbl_Contract_Maintenance.[Supplier ID]
  3.  
Total Contracts
Expand|Select|Wrap|Line Numbers
  1. SELECT [No of Maintenance Contracts], [No of General Contracts],  [No of Maintenance Contracts] + [No of General Contracts] As TotalContracts
  2. FROM qselGeneralContracts, qselMaintenanceContracts
  3.  
Reply