Re: Getting Totals From Two Different Tables In A Query
- From: New Guy <NewGuy@xxxxxxxxx>
- Date: Sun, 31 Jul 2005 19:11:29 GMT
On Sun, 31 Jul 2005 12:38:42 +0800, "Allen Browne"
<AllenBrowne@xxxxxxxxxxxxxx> wrote:
>Your 2 existing queries give you the total for all invoices for each client,
>and the total for all payments for all clients.
>
>You could now create a 3rd query, using the first 2 as input "tables". In
>the upper pane of this query design, if you see no line between the 2
>"tables", then drag Query1.ClientID onto Query2.ClientID. Then double-click
>the join line: Access pops up a dialog with 3 options. Choose the one that
>says:
> All records from the invoice query, and any matches from ...
>This handles the case where a client has invoices but no payments.
>
>It would also be possible to do it in one query with a SQL statement
>something like this:
>
>SELECT [Invoice].[ClientID] AS Client,
> Sum([Invoice].[InvoiceTotal]) AS Charges,
> (SELECT Sum([Payment].[Amount]) AS Payments
> FROM Payment
> WHERE (PaymentDate< #10/06/04#)
> AND (Payment.ClientID = Invoice.ClientID)) AS Payments
>FROM Invoice
>WHERE InvoiceDate< #10/06/04#
>GROUP BY [Invoice].[ClientID] ;
>
>This kind of thing is called a subquery. More info:
> http://support.microsoft.com/?id=209066
Allen,
This is working great. I had tried to make a subquery like this
yesterday but I kept getting errors.
Thanks a lot for helping me.
When there is no payment for one of the clients, the query inserts a
blank in the payment field, even though I have a default value of 0
for all the fields except Client. Is it possible to make it insert a
0 instead of a blank.
Thanks again.
.
- Follow-Ups:
- Re: Getting Totals From Two Different Tables In A Query
- From: Allen Browne
- Re: Getting Totals From Two Different Tables In A Query
- References:
- Getting Totals From Two Different Tables In A Query
- From: New Guy
- Re: Getting Totals From Two Different Tables In A Query
- From: Allen Browne
- Getting Totals From Two Different Tables In A Query
- Prev by Date: Re: Report Group Section Footer displaying Totals
- Next by Date: Re: How to 'dump' all standard and class module code lines into an Access table
- Previous by thread: Re: Getting Totals From Two Different Tables In A Query
- Next by thread: Re: Getting Totals From Two Different Tables In A Query
- Index(es):
Relevant Pages
|