Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which command would execute faster? Seek & Do while or S
Message
From
28/03/2006 08:06:24
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
27/03/2006 22:51:59
Sonny Tabano
Trams Printwork, Inc.
Mabalacat, Philippines
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01108228
Message ID:
01108305
Views:
17
>Hi everyone,
>
>Which of the commands below would execute faster assuming you have a million records and 200,000 of this records corresponds to the CUST_ID to compute the OrderAmount?
>
>1. (PRG)
>
>Local lnTotalOrder, lcCustID
>
>lnTotalOrder = 0
>lcCustID = "0008"
>
>Seek &lcCustID    && Seek "0008"
>Do while Customer.Cust_ID=&lcCustID
>   lnTotalOrder = lnTotalOrder + Customer.OrderAmount
>   Skip
>Enddo
>Return (lnTotalOrder)
>
You should avoid using & as often as possible. This should be faster than what you had:

Seek m.lcCustID && Seek "0008"
scan while Cust_ID = m.lcCustID
lnTotalOrder = m.lnTotalOrder + OrderAmount
Endscan

>
>or
>
>2. (SQL)
>
>Select Customer.Cust_ID, sum(Customer.OrderAmount) As lnTotalOrder;
>from Customer  into cursor temp where Customer.Cust_ID="0008" Group by Customer.Cust_ID
>
The answer to your question is not easy. SELECT will read the entire cust_id index from the server to the client PC's CPU to determine which records to examine. It will then read the record data while doing the sum.

The DO WHILE will read very little index tag information before starting to read the record data.
Previous
Reply
Map
View

Click here to load this message in the networking platform