Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am trying to sum but duplicates are a problem

Status
Not open for further replies.

planetdrouin

Technical User
Dec 29, 2001
36
US
Hello,

I have a query which essentially brings in two tables. They are TblInvoices and TblReceipts.

Both tables look like (with some other fields):
Date InvoiceID ClientID Amount

However, the InvoiceID is unique in TblInvoices but not in TblReceipts as some customers pay in multiple instalments. I am trying to run a query which will provide the following output:

InvoiceID ClientID AmountInvoiced AmountReceived

The catch is that I want the user to be able to enter a parameter which asks for the month the invoice was either sent or received. Since multiple AmountReceived exist for some invoices, the total AmountInvoiced is incorrect (multiplied by the number of instalments the customer made).

My SQL is as follows:

SELECT TblInvoices.InvoiceID, TblInvoices.ClientID, "insert complicated formula" AS AmountInvoiced, "insert less complicated formula" AS AmountReceived, Format(IIf([forms]![frmUserInput].[DateType]="Invoiced",[InvoiceDate],[DateReceived]),"m") AS [Month]
FROM TblInvoices LEFT JOIN TblReceipts ON TblInvoices.InvoiceID = TblReceipts.InvoiceID
GROUP BY TblInvoices.InvoiceID, TblInvoices.ClientID, Format(IIf([forms]![frmUserInput].[DateType]="Invoiced",[InvoiceDate],[DateReceived]),"m");

What do I need to do in order to have it only count the AmountInvoiced once but all of the AmountReceived while still allowing the user to pick a sent or received date. Any help is greatly appreciated.

Lawrence
 
show the sample output of your sql
and the output you need
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top