Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query help part 2
Message
De
18/10/2004 15:05:18
Jim Winter
Jim Winter Consulting
Hinesburg, Vermont, États-Unis
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00952381
Message ID:
00952402
Vues:
14
>I have a customer table that has a row for each of the last 15 items the
>customer has ordered. Now I need to build a table that has one row per
>customer with each of the 15 items on that one row. So I need to take 15 rows
>of customer_no, Item_no and create a table of customer_no, item_no1,
>item_no2, item_no3, etc.
>
>Any ideas?
>
>Thanks
>
>Brenda


Brenda,

First create a cursor with the desired structure, ie., Customer_No, Item_No1, Item_No2, etc. Call it FlatCustomer.

Then
LOCAL lcCustomer_No, lnIndex
USE FlatCustomer 
SELECT 0
USE Customer ORDER Customer_No
lcCustomer_No = ""
lnIndex = 0
SCAN

   DO CASE
      CASE lcCustomer_No == Customer.Customer_No AND ;
           BETWEEN(lnIndex,2,9)
         REPLACE ("FlatCustomer.Item_No" + STR(lnIndex,1)) WITH ;
            Customer.ItemNo
      CASE lcCustomer_No == Customer.Customer_No AND ;
           BETWEEN(lnIndex,10,15)
         REPLACE ("FlatCustomer.Item_No" + STR(lnIndex,2)) WITH ;
            Customer.ItemNo
      CASE lcCustomer_No # Customer.Customer_No 
         lcCustomer_No = Customer.Customer_No
         lnIndex = 1
         INSERT INTO FlatCustomer (Customer_No, Item_No1) ;
            VALUES (lcCustomer_No, Customer.Item_No)
   ENDCASE
   lnIndex = lnIndex + 1

ENDSCAN
Regards,
Jim
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform