PDA

View Full Version : Running Sum


kiwieur
04-09-2009, 03:24 PM
I have a recordset that pulls data from an access database based on certain criteria and therefore the number of rows displayed can vary from 1 to many.

2 of the fields in the recordset display the following data

Order Type
Order Qty

and an example would be

Row No. Order Type Order Qty
1 Top Up 10000
2 Call Off 5000
3 Call Off 3000

I also have a field from another recordset that displays the "Total Stock" value from the database

Now what I would like to do is have another field next to order qty named "Current Stock" and depending on the order type either add or subtracts values. This value would be calculated as follows using the example above


Order Type Order Qty Current Stock
Top Up 10000 =TotalStock + Row1 order qty
Call Off 5000 = row1 Currentstock - order qty
Call Off 3000 = row2 Currentstock - order qty

and so on

so the above example figures would be as shown below assuming that the "Total Stock Qty" is 12000


Order Type Order Qty Current Stock
Top Up 10000 22000
Call Off 5000 17000
Call Off 3000 14000

If anyone can help me at all I would appreciate it very much

Regards

Paul :confused:

mangofreak
04-12-2009, 08:34 PM
Is the sum being done dynamically when someone sells or orders from the stock?

I'm not sure I understand but I would do something like:


<%
Dim qty1, qty2, currentstock

qty1 = Request.QueryString(qty1)
qty2 = Request.QueryString(qty2)
currentstock = (qty1 - qty2)
%>

Then currentstock would go in your update from as a hidden field updating your currentstock

I may be way off but I would ned to understand your concept first.

Hope it helps, at least a little

Javier