Cindy
Tue Oct 11 12:26:40 CDT 2005
Hi William,
Keeping a total value in a row where it depends on other values is tricky,
and, as you've discovered, it's easy to get wrong values.
When you use SQL to get the total (as for a report), performance depends on
good indexing. Do you have indexes on your Account field?
Here's one idea, but it depends on denormalizing the data a little: keep the
totals in a separate table that's 1-1 to the Accounts table (and Stock
table). Use Insert/Update/Delete triggers on the line items table(s) to
update the values in the Totals table. You can also run a batch job
overnight to recalculate the totals, just in case they're wrong.
--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy_winegarden@msn.com www.cindywinegarden.com
Blog:
http://spaces.msn.com/members/cindywinegarden
"William" <William@discussions.microsoft.com> wrote in message
news:AE9ECCF1-7721-4D05-8BBC-86595A2BE7CE@microsoft.com...
> How to make accumulated data (e.g., total amount, balance) correct all the
> time? Many years ago, I did an order system and found the total amount was
> not right sometimes. The order system is pretty complicated and it's not
> easy
> to find where it is wrong. I know I can add transaction log for this
> field.
> But I don't think that's the best way. The original code was something
> like
> TotalAmount= TotalAmount-OldItemAmount+NewItemAmount. I changed it to
> Select
> Sum(NewItemAmount) as TotalAmount. That means recalculate it every time.
> And
> then the total value has never been wrong. The biggest problem for this
> method is performance. We may not able to recalculate everything, say
> stock
> on hand. The biggest problem is balance for every account in general
> ledger.
> Do you have any ideas to make them correct all the time?
> TIA.
>
>