Nz function

Joined
Aug 9, 2009
Messages
11
Reaction score
0
I am trying to subtract one field from another. At the moment, there are values in one field, but not in the other. Thus, the result of the subtractions should equal the values in the field has entries.

Both of these selected "tables" for the query are actually sub-queries that total invoice amounts by customer. The results of one of the sub queries shows the appropriate numbers. And, since there are no entries yet in the other field, that query yields no results. Thus, I believe that the "answers" to the calculations should exactly equal the entries in the table with values.

Of course I need to convert all those pesky null values to zeros. Rather than getting the expected long list of results, I am getting no result.

(The advantage with keeping 1 table free of any entries is that it isolates the issue of when there really is no number for some customers in the real data)

The SQL for this query that calculates the difference in the two totals is:
SELECT DISTINCTROW Qry_Sub2_TotalInvByCustID.SumOfInvoiceCommisions, Qry_Sub2_TotalCommPdByCustID.SumOfCommPd, Qry_Sub2_TotalCommPdByCustID.[CUSTOMER ID], (Nz([Qry_Sub2_TotalCommPdByCustID].[SumOfCommPd],0)-Nz([Qry_Sub2_TotalInvByCustID].[SumOfInvoiceCommisions],0))/Nz([Qry_Sub2_TotalCommPdByCustID].[SumOfCommPd],0) AS CommVariance
FROM Qry_Sub2_TotalCommPdByCustID INNER JOIN Qry_Sub2_TotalInvByCustID ON Qry_Sub2_TotalCommPdByCustID.[CUSTOMER ID] = Qry_Sub2_TotalInvByCustID.CustID
ORDER BY (Nz([Qry_Sub2_TotalCommPdByCustID].[SumOfCommPd],0)-Nz([Qry_Sub2_TotalInvByCustID].[SumOfInvoiceCommisions],0))/Nz([Qry_Sub2_TotalCommPdByCustID].[SumOfCommPd],0) DESC;

Then again, possibly the problem is in the query that calculates totals for the table with no entries. The SQL for that query is:
SELECT DISTINCTROW Sum(Qry_Sub_InvoicesForMonth.MonthlyCommAmt) AS SumOfInvoiceCommisions, Qry_Sub_InvoicesForMonth.CustID
FROM Qry_Sub_InvoicesForMonth
GROUP BY Qry_Sub_InvoicesForMonth.CustID;

I would sure appreciate any help with making this work.
 

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

Similar Threads

Cartesian join in Access 0
NZ function 1
NZ function 1
Nz(null values in queries, 0) 2
Can I use an IIF statement with the NZ function? 2
Summation fails if Nz used 2
NZ 5
Query Calc. is Mult. # of Table rows--Y? 3

Top