Nested Query needed

juster21

Well-known Member
Joined
Jun 3, 2005
Messages
867
I have a table that I am using for tracking data on a yearly basis. A record is created at the end of the year for a customer and contains Control, RenewalMonth and TerminalAmount.
The TerminalAmount is everything. It is a sum of money from each month in the year. I only calculate this value once a year, at the end of the year.
My problem/confusion is in the second year. If there is a value in the TerminalAmount (the previous years sum total) I need to add it to the sum of all months from this year and update the record.

<code>Control | RenewalMonth | TerminalAmount <br>
0123456 | 01 | $1000.00 </code>

For the example we can assume the dollar amounts are the same for each year.
So, in the second year the record for this group would look like this...

<code>Control | RenewalMonth | TerminalAmount <br>
0123456 | 01 | $2000.00 </code>
...based on the $1000 plus this years $1000.

Can I do that in 1 query or a nested query? Should I? Is the simple answer to just add an additional column and use that?

Thanks for your time on this!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I use this query to get both amount:
SELECT Sum(tblLiability.TerminalReserve) AS SumOfTerminalReserve, tblTerminalReserve.TerminalAmount
FROM tblTerminalReserve INNER JOIN tblLiability ON tblTerminalReserve.Control = tblLiability.Control
WHERE (((tblTerminalReserve.Control)="0686867"))
GROUP BY tblTerminalReserve.TerminalAmount;

And then this query to sum the 2 values:
SELECT [SumOfTerminalReserve]+[TerminalAmount] AS SumOfAll
FROM TermReserveAmounts;

So I should be able to nest these queries, right?



I have a table that I am using for tracking data on a yearly basis. A record is created at the end of the year for a customer and contains Control, RenewalMonth and TerminalAmount.
The TerminalAmount is everything. It is a sum of money from each month in the year. I only calculate this value once a year, at the end of the year.
My problem/confusion is in the second year. If there is a value in the TerminalAmount (the previous years sum total) I need to add it to the sum of all months from this year and update the record.

<code>Control | RenewalMonth | TerminalAmount <br>
0123456 | 01 | $1000.00 </code>

For the example we can assume the dollar amounts are the same for each year.
So, in the second year the record for this group would look like this...

<code>Control | RenewalMonth | TerminalAmount <br>
0123456 | 01 | $2000.00 </code>
...based on the $1000 plus this years $1000.

Can I do that in 1 query or a nested query? Should I? Is the simple answer to just add an additional column and use that?

Thanks for your time on this!
 
Upvote 0

Forum statistics

Threads
1,221,792
Messages
6,161,995
Members
451,735
Latest member
Deasejm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top