Join, Total, Update
As long as we've been using Xbase, we've heard that these three commands should be avoided. At least as far back as FoxBase+, the manuals warn that JOIN may be very slow and can overrun available disk space.As a result of these dire warnings, we never looked very hard at these commands (though we've occasionally been called on to maintain code that uses them). Now that we've done so, we've decided it's just as well. They're hard to use, limited in capability, and can be extremely slow.
Usage |
JOIN WITH cAlias | nWorkArea TO cTable FOR lForExpression [ FIELDS cFieldList ] NOOPTIMIZE |
JOIN has a bug when dealing with long field names. In the newly created table, all field names are truncated to 10 characters or less. This makes some sense since the table is created as a free table. |
Example |
* Here's an example involving very small tables so you * can see the result in this lifetime. It fails in * versions VFP 5 and later, but does work in VFP 3. USE category SELECT 0 USE products JOIN WITH category TO temp FOR category_id=category.category_id * Here's the SELECT-SQL equivalent: SELECT * FROM category, products ; WHERE category.category_id=products.category_id ; INTO TABLE temp |
Usage |
TOTAL TO cTable ON uField [ FIELDS nNumericFieldList ] [ Scope ] [ FOR lForExpression ] [ WHILE lWhileExpression ] [ NOOPTIMIZE ] |
Example |
* We couldn't find a way to use TOTAL with the sample * TasTrade database that comes with Visual FoxPro. * The table in this example is from the Tutorial * data that shipped with earlier versions of FoxPro. USE Detail && Invoice detail lines * Compute invoice totals TOTAL ON ino TO InvTotal FIELDS Ltotal |
Usage |
UPDATE ON uJoinFieldName FROM cTable REPLACE uFieldName1 WITH eExpression1 [ , uFieldName2 WITH eExpression2 [ , ... ] ] [ RANDOM ] |
Example |
* Again, we can't see a way to use UPDATE with * the nicely normalized TasTrade database. * The example uses the old, less normalized, * Tutorial data. SELECT 0 USE Detail SELECT 0 USE Invoices * Clear out existing invoice totals. REPLACE ALL iTotal WITH 0 * Now recompute. UPDATE ON ino FROM Detail ; REPLACE iTotal WITH iTotal+Detail.Qty*Detail.Price |
See Also |