Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query help part 2
Message
From
18/10/2004 15:05:18
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00952381
Message ID:
00952402
Views:
13
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform