RE: Total to <Fieldname>... is <FieldExpr> ok? by Mark
Mark
Thu Sep 20 11:02:07 PDT 2007
Hi Lew,
From Hacker's Guide to Visual Foxpro
TOTAL TO cTable ON uField
[ FIELDS nNumericFieldList ]
[ Scope ]
[ FOR lForExpression ]
[ WHILE lWhileExpression ]
[ NOOPTIMIZE ]
TOTAL is similar to working with GROUP BY in SELECT-SQL, but far more
limited. It groups records from the table open in the current work area based
on the listed field (uField) and totals the numeric fields listed in
nNumericFieldList. If FIELDS is omitted, all numeric fields are totaled. A
new table is created to hold the result. All fields from the original table
are included in the result. You can limit the records included in the
computation using the Scope, FOR and WHILE clauses.
So what else is wrong with TOTAL? The new table created has the same
structure as the original. If the total for a field is too big to fit, you
lose precision. Also, since all fields are carried along, you get random
results for fields that aren't either totaled or listed in the ON clause.
(Actually, this is the same thing that happens when you include extraneous
fields in a GROUPed query, but at least there you have a chance to omit
them.) TOTAL is limited to working with a single tableâ??you can't match up
records from multiple tables. Finally, you can't compute expressions, only
sum existing fields, so you can't do things like total (quantity*unit price)
to get an invoice total.
hth
Mark
"Lew" wrote:
> I'm looking at some old code that uses the total to command. The help file
> specifies that the syntax is total to <TableName> on <FieldName> (ie group on
> a single field value), but the code I see uses a field expression, ie
> <Field1+Field2+Fieldx+etc>. It seems to work ok. Can anyone confirm that this
> will always be the case or are there gotcha's.... like what happens when the
> FIeldExpression reaches a certain length or the actual field widths exceed a
> certain total.
> -Lew