UNC_Access
Registered User.
- Local time
- Today, 18:00
- Joined
- Oct 24, 2012
- Messages
- 42
Hi. I am nearly positive I'm not asking this question in the most efficient method possible, so any advice is welcome! I'm new to Access and am not a programmer (as is obvious).
Basically:
1. I have two tables: Table1 and Table2
2. Table1 has two fields: ID Number and Amount
3. Table2 has two fields: ID Number and Repayment
4. I need to create a query (linking ID Number) which calculates: Sum of Table1.Amount - Sum of Table2.Repayment for each ID Number to provide a ResultingBalance (please excuse the horrible wording). To reiterate:
-4a. In respect to Table1, I want to sum all amounts for each ID Number
-4b. In respect to Table2, I want to sum all repayments for each ID Number
-4c. Ultimately, my goal is to take the sum of all amounts described in #4a (above) and subtract the sum of all amounts described in #4b (above) to calculate a remaining balance
My issue, of course, is explained with a quick example:
Table1 has a record:
ID Number: 1111
Amount: $100
But Table2 contains no ID Number 1111 (and thus no Repayment amount)
Therefore, when I perform the query in #4 (above), for ID Number 1111:
Amount is $100
Repayment is blank
ResultingBalance is blank
I am trying to use the NZ function to substitute nulls with a zero in the query.
Is this possible?
Here is my SQL code if it helps (don't know where to put the NZ function):
SELECT Table1.[ID Number], Sum(Table1.Amount) AS SumOfAmount, Sum(Table2.Repayment) AS SumOfRepayment, Sum([Table1].[Amount]-[Table2].[Repayment]) AS Balance
FROM OP INNER JOIN Table2 ON Table1.[ID Number] = Table2.[ID Number]
GROUP BY Table1.[ID Number];
Basically:
1. I have two tables: Table1 and Table2
2. Table1 has two fields: ID Number and Amount
3. Table2 has two fields: ID Number and Repayment
4. I need to create a query (linking ID Number) which calculates: Sum of Table1.Amount - Sum of Table2.Repayment for each ID Number to provide a ResultingBalance (please excuse the horrible wording). To reiterate:
-4a. In respect to Table1, I want to sum all amounts for each ID Number
-4b. In respect to Table2, I want to sum all repayments for each ID Number
-4c. Ultimately, my goal is to take the sum of all amounts described in #4a (above) and subtract the sum of all amounts described in #4b (above) to calculate a remaining balance
My issue, of course, is explained with a quick example:
Table1 has a record:
ID Number: 1111
Amount: $100
But Table2 contains no ID Number 1111 (and thus no Repayment amount)
Therefore, when I perform the query in #4 (above), for ID Number 1111:
Amount is $100
Repayment is blank
ResultingBalance is blank
I am trying to use the NZ function to substitute nulls with a zero in the query.
Is this possible?
Here is my SQL code if it helps (don't know where to put the NZ function):
SELECT Table1.[ID Number], Sum(Table1.Amount) AS SumOfAmount, Sum(Table2.Repayment) AS SumOfRepayment, Sum([Table1].[Amount]-[Table2].[Repayment]) AS Balance
FROM OP INNER JOIN Table2 ON Table1.[ID Number] = Table2.[ID Number]
GROUP BY Table1.[ID Number];