Query Sum Returning total times 3

  • Thread starter Regan via AccessMonster.com
  • Start date
R

Regan via AccessMonster.com

Hello anyone

I have this query that returns the values i want. When i use another query
to sum the query it returns the total times 3. i just want to return the
total.

This is the query that returns the right values:

QryTEST

SELECT tblcodes.TSCatagory, TS1.entryID, TS1.entrydate,
TS1.employeeID, tblcodes.CodeID, tblcodes.chargetype,
IIF(tblcodes.chargetype="employee",IIf((SELECT EMC1.employconfID
FROM tblemployconf AS EMC1
WHERE TS1.employeeID=EMC1.employeeID
and
(SELECT Min(EMC.ChangeDate) AS Min
FROM tblemployconf AS EMC
WHERE TS1.entrydate<EMC.changedate;)=EMC1.changeDate;) is null,
(SELECT EMC2.chargeoutrate FROM tblemployconf AS EMC2
WHERE TS1.employeeID=EMC2.employeeID and EMC2.changeDate is null;),
(SELECT EMC1.chargeoutrate
FROM tblemployconf AS EMC1
WHERE TS1.employeeID=EMC1.employeeID
and
(SELECT Min(EMC.ChangeDate) AS Min
FROM tblemployconf AS EMC
WHERE TS1.entrydate<EMC.changedate;)=EMC1.changeDate;) ),
IIF(tblcodes.chargetype="code", tblcodes.chargerate,Null)) AS ChargeRate, TS1.
Units
FROM tblcodes INNER JOIN (tblEmployConf
INNER JOIN tbltimesheet AS TS1 ON tblEmployConf.EmployeeID = TS1.EmployeeID)
ON tblcodes.CodeID =TS1.CodeID
WHERE TS1.CodeID = tblcodes.CodeID;

Sample returns:

TSCatagory EntryID EntryDate employeeID codeID
chargetype ChargeRate

Topo 2 16/11/06 3
5 employee $45
Topo 3 17/11/06 3
5 employee $45
Cadas 3 18/11/06 3
9 employee $45

Now when i query the query with:

SELECT QryTEST.TSCatagory, Sum(QryTEST.ChargeRate) AS SumOfChargeRate
FROM QryTEST
GROUP BY QryTEST.TSCatagory;

i get the results:

TSCatagroy SumOfChargeRate
Topo 270 <--$90x3 - Why?
Cadas 135

What i want it to show is

TSCatagroy SumOfChargeRate
Topo 90
Cadas 45

Hope someone can help with this

Thanks
 
Top