View Full Version : Sum records with no value


mtagliaferri
03-20-2009, 01:31 AM
Hi, I have query which combines and sums values from a query and a table, query “”qryDutyPaySimulation” has entries for all months but the table “tblAdditionalAllowances” has not, I am trying to sum for every month the total for the two tables or the difference, for those fields with no value it will not sum the records, and of course I do not have all months values in the “tblAdditionalAllowances”
SELECT qryDutyPaySimulation.PSR, qryDutyPaySimulation.[Tot Of Trips], qryDutyPaySimulation.[Tot Of Days], qryDutyPaySimulation.[Night Stops], qryDutyPaySimulation.[Tot Flying Time], qryDutyPaySimulation.[Tot TAFB], qryDutyPaySimulation.DutyPayRate, qryDutyPaySimulation.[Tot Duty Pay], Sum(tblAdditionalAllowances.AmmountAdditionalAllow ances) AS [Additional Allowance], tblPayslip.FDPTaxAllowance, tblPayslip.FDPNTaxAllowance, (tblPayslip.FDPTaxAllowance)+(tblPayslip.FDPNTaxAl lowance) AS TOT, [TOT]-[Tot Duty Pay] AS [Difference 1], tblPayslip.AdditionalTaxVariable, tblPayslip.AdditionalNTaxVariable, (tblPayslip.AdditionalTaxVariable) +(tblPayslip.AdditionalNTaxVariable) AS [TOT ADD], [TOT ADD] - [Additional Allowance] AS [Difference 2]
FROM (qryDutyPaySimulation LEFT JOIN tblAdditionalAllowances ON qryDutyPaySimulation.PSR = tblAdditionalAllowances.PSR) INNER JOIN tblPayslip ON qryDutyPaySimulation.PSR = tblPayslip.PayslipPSR
GROUP BY qryDutyPaySimulation.PSR, qryDutyPaySimulation.[Tot Of Trips], qryDutyPaySimulation.[Tot Of Days], qryDutyPaySimulation.[Night Stops], qryDutyPaySimulation.[Tot Flying Time], qryDutyPaySimulation.[Tot TAFB], qryDutyPaySimulation.DutyPayRate, qryDutyPaySimulation.[Tot Duty Pay], tblPayslip.FDPTaxAllowance, tblPayslip.FDPNTaxAllowance, tblPayslip.AdditionalTaxVariable, tblPayslip.AdditionalNTaxVariable;

Can you please advice me :D

boblarson
03-20-2009, 07:15 AM
Use the NZ function to wrap around the fields so that it can convert nulls to zeros which will then work for a sum function.

mtagliaferri
03-21-2009, 11:50 PM
Great,thankyou so much :p
Marco