cannot sum null; not zero

R

Rick Stahl

In a query I am trying to sum currency fields from subqueries. Some of
these fields are blank because no value should be there. Where there is
values in all fields of a given record, summation works fine. However
wherever there is a blank field, no sum is returned. Do I have to make all
the blank fields zero or is there a way I can sum the fields "as is" by
somehow stating somewhere "if null, then equals zero" ? Thank you.
 
K

Ken Snell \(MVP\)

SELECT Sum(Nz(FieldName, 0)) AS MySum
FROM Tablename;

The Nz function will substitute the value 0 for a Null value in the field
when doing the sum calculation.
 
R

Rick Stahl

Thank you. I understand what you are saying but I am not real familiar with
SQL. I apologize for my ignorance but I only am familiar with using the
"Design View" in Access. Part of the SQL includes:

SELECT [qryHourlyWeeklyNon-TaxDeductions].curMiscDeduction,
[qryHourlyWeeklyNon-TaxDeductions].tblWeeklyHoursAttendance.strComments,
[qryHourlyWeeklyNon-TaxDeductions].curDomRel,
[qryHourlyWeeklyNon-TaxDeductions].curOtherDeductions,
[qryHourlyWeeklyNon-TaxDeductions].[tblNon-TaxDeductions].strComments,
[qryHourlyWeeklyNon-TaxDeductions].[curTotalNon-TaxDeductions],
[curTotalTaxes]+[curTotalNon-TaxDeductions] AS curTotalDeductions

I may need help with the format. Thank you.
 
F

fredg

Thank you. I understand what you are saying but I am not real familiar with
SQL. I apologize for my ignorance but I only am familiar with using the
"Design View" in Access. Part of the SQL includes:

SELECT [qryHourlyWeeklyNon-TaxDeductions].curMiscDeduction,
[qryHourlyWeeklyNon-TaxDeductions].tblWeeklyHoursAttendance.strComments,
[qryHourlyWeeklyNon-TaxDeductions].curDomRel,
[qryHourlyWeeklyNon-TaxDeductions].curOtherDeductions,
[qryHourlyWeeklyNon-TaxDeductions].[tblNon-TaxDeductions].strComments,
[qryHourlyWeeklyNon-TaxDeductions].[curTotalNon-TaxDeductions],
[curTotalTaxes]+[curTotalNon-TaxDeductions] AS curTotalDeductions

I may need help with the format. Thank you.

Ken Snell (MVP) said:
SELECT Sum(Nz(FieldName, 0)) AS MySum
FROM Tablename;

The Nz function will substitute the value 0 for a Null value in the field
when doing the sum calculation.

Select ... etc....
Nz([curTotalTaxes],0)+Nz([curTotalNon-TaxDeductions],0) AS
curTotalDeductions

Look up the Nz function in VBA help. It's very useful in other
situations as well.
 
R

Rick Stahl

Thank you very much ! It worked nicely.


fredg said:
Thank you. I understand what you are saying but I am not real familiar
with
SQL. I apologize for my ignorance but I only am familiar with using the
"Design View" in Access. Part of the SQL includes:

SELECT [qryHourlyWeeklyNon-TaxDeductions].curMiscDeduction,
[qryHourlyWeeklyNon-TaxDeductions].tblWeeklyHoursAttendance.strComments,
[qryHourlyWeeklyNon-TaxDeductions].curDomRel,
[qryHourlyWeeklyNon-TaxDeductions].curOtherDeductions,
[qryHourlyWeeklyNon-TaxDeductions].[tblNon-TaxDeductions].strComments,
[qryHourlyWeeklyNon-TaxDeductions].[curTotalNon-TaxDeductions],
[curTotalTaxes]+[curTotalNon-TaxDeductions] AS curTotalDeductions

I may need help with the format. Thank you.

Ken Snell (MVP) said:
SELECT Sum(Nz(FieldName, 0)) AS MySum
FROM Tablename;

The Nz function will substitute the value 0 for a Null value in the
field
when doing the sum calculation.
--

Ken Snell
<MS ACCESS MVP>


In a query I am trying to sum currency fields from subqueries. Some of
these fields are blank because no value should be there. Where there
is
values in all fields of a given record, summation works fine. However
wherever there is a blank field, no sum is returned. Do I have to make
all the blank fields zero or is there a way I can sum the fields "as
is"
by somehow stating somewhere "if null, then equals zero" ? Thank you.

Select ... etc....
Nz([curTotalTaxes],0)+Nz([curTotalNon-TaxDeductions],0) AS
curTotalDeductions

Look up the Nz function in VBA help. It's very useful in other
situations as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top