|
Solaras Wanderer
Joined: 11 Mar 2002 Posts: 93
|
Posted: Thu Aug 03, 2006 9:36 am
Database and math |
I have a database that I update every Friday night and what I can't figure out is how to add(math) to current fields.
Code: |
#NEW AccountBalances {Name=%1|Deposited=%2|Debits=%3|Expenses=%4|Net=%5} |
What I do is every Friday night, I check the totals and clear the log for the following week. I need to add the weekly totals to the fields for each person.
Bob 12000 2000 4000 6000
John 20000 15000 10000 -5000
Note that the order of names is not always the same as it is sorted by Net total. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Thu Aug 03, 2006 3:02 pm |
#VAR recordsToUpdate {%find(%1, "AccountBalances")}
#IF (%numitems(@recordsToUpdate) > 0) {#VAR updatedRecord {%dbget(%item(@recordsToUpdate, 1))};#ADDKEY updatedRecord {Deposited=%eval(%db(@updatedRecord, "Deposited") + %2)|Debits=%eval(%db(@updatedRecord, "Debit") + %3)|Expenses=%eval(%db(@updatedRecord, "Expenses") + %4)|Net=%eval(%db(@updatedRecord, "Net") + %5)};#DBPUT %item(@recordsToUpdate, 1) @updatedRecord} {#NEW AccountBalances {Name=%1|Deposited=%2|Debits=%3|Expenses=%4|Net=%5}}
This will update the first record that matches the name in %1. If no record matches, it will create a new one. This script assumes that the first field in the AccountBalances view is Name. |
|
_________________ Kjata |
|
|
|
Solaras Wanderer
Joined: 11 Mar 2002 Posts: 93
|
Posted: Fri Aug 04, 2006 1:55 am |
Thank you so much! This works exactly how I wanted.
|
|
|
|
|
|