TOTAL Command Sums Only One Key Field

Last reviewed: April 17, 1995
Article ID: Q88889
The information in this article applies to:
  • Microsoft FoxBASE+ for MS-DOS, versions 1.21 and 2.1
  • Microsoft FoxPro for MS-DOS, versions 1.0, 1.01, 1.02, and 2.0

SUMMARY

In FoxBASE+ and FoxPro, the TOTAL command computes the total of only one key field. This field must be the first field in the index expression.

Syntax

   TOTAL TO <file> ON <key>
   [<scope>]
   [FIELDS <list>]
   [FOR <expL>]
   [WHILE <expL>]

MORE INFORMATION

The TOTAL command computes the total of the numeric fields of records in the currently selected database that match the <key> expression and places the total into the corresponding fields of records in a second database.

The current database must be sorted on the <key> expression or have an index enabled on the <key> expression. If the output <file> does not already exist, FoxBASE+ or FoxPro creates the file with a .DBF default extension.

By default, the TOTAL command totals all numeric fields unless the FIELDS clause is specified.

If the numeric fields in the database file that receives the totals are not wide enough to contain the totals, numeric overflow may occur. When overflow occurs, FoxBASE+ and FoxPro conserve the most- significant digits of the totals, as follows:

  1. The number of decimal places in the numeric representation is reduced and the resulting total is rounded.

  2. If the rounded total does not fit and the total field is 7 digits wide or wider, scientific notation is used to represent the total.

  3. If the field is not wide enough to accommodate scientific notation, asterisks replace the contents of the total field.

Example

   USE Video INDEX Rating
   TOTAL TO V_stotal ON Rating FIELDS Rating, Num_sold
   * V_stotal was not predefined.

   USE V_stotal
   LIST rating, num_sold
   Record#     RATING     NUM_SOLD
         1     G          675
         2     N/R       2205
         3     PG       21244
         4     R        14351


Additional reference words: FoxDos 1.00 1.01 1.02 1.21 2.00 2.10
KBCategory: kbusage kbprg
KBSubcategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 17, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.