Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have learned more through this forum than I did on a two day course. Thanks to everyone for their help and other postings that I have found useful..."

Geography

Where in the world do Tek-Tips members come from?
philthoms (Programmer)
20 Sep 12 13:25
Hello,
I have a database file with just a few fields that require totalling into a totals field eg 'replace totals with field1+field2+field3' etc. there are only five fields to be totalled at the moment but this may increase to at least fifteen.
Is there a betted method of totalling many fields than the long winded way with the replace command?
Thanks
Helpful Member!  OlafDoschke (Programmer)
20 Sep 12 13:44
What's longwinded with the replace command?

Besides a normal table layout would not total 15 fields of a record into 1 total field but would have one numeric field to take a sum by aggregation eg SUM(field). And you wouldn't store that total, as it's a computed value, so it would be storing redundant data. The only good redundancy in data is backups.

Bye, Olaf.
Helpful Member!  MikeLewis (Programmer)
20 Sep 12 14:23
I suppose if you really wanted to, you could do it in a loop, something like this:

CODE

SELECT MyTable
lnTotal = 0
FOR lnI = 1 TO 15
  lnTotal = lnTotal + EVALUATE(FIELD(lnI))
ENDFOR 
REPLACE TotalField WITH lnTotal 

But is it worth it? Unless you will be writing this code many times, you might as well stick to your original plan:

CODE

REPLACE Totals WITH Field1 + Field2 + Field3 + ... etc. 

Do also take note of Olaf's point about redundancy. There's little pointing in storing a total when it's trivially easy to calculate it as it's needed.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close