Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Solaras
Wanderer


Joined: 11 Mar 2002
Posts: 93

PostPosted: 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.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: 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
Reply with quote
Solaras
Wanderer


Joined: 11 Mar 2002
Posts: 93

PostPosted: Fri Aug 04, 2006 1:55 am   
 
Thank you so much! This works exactly how I wanted.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net