>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. >>
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 */ ENDSCANThis 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.