Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Scan endscan break
Message
De
17/12/2007 17:44:28
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01276291
Message ID:
01276354
Vues:
18
>I another database language I use there is a powerful FOR loop...
>
>
>for each customer where customer.country='USA'
>    break by customer.state no-lock:
>
>    if first-of(customer.state) then do:
>        /* do something with first record */
>    end.
>
>    /* do something with records */
>
>    if last-of(customer.state) then do:
>        /* do something with last record  */
>    end.
>
>end.
>
>
>Scan endscan sort of does this but I cannot break. Can VFP do something like this?
Here's another approach which doesn't do all the record skipping.
SELECT DISTINCT state FROM customer WHERE country = "USA" INTO CURSOR crsStates
SCAN
    m.State = crsStates.state
    SELECT * FROM customer WHERE state = m.state
    /* Do logic for first record */
    SCAN
       /* Do logic for each record
    ENDSCAN
    /* Do logic for last record */
ENDSCAN
This MAYBE won't produce the same results as my first effort. One problem is that the states might not be in the same sequence as in the customer table and that the records within each state might not be in the same sequence. You can always put ORDER BY's in the various selects if necessary.

The second (but unlikely) problem is you have several different groupings for the first state. For example, if customer is actually ordered on Country,MONTH(Inv_Date),State then the original code would produce a several groupings for each state while this would only produce one group. If, as I suspect is the case, you actually have ordered the data by Country, State then this variation may be more readable.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform