Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Statement
Message
From
29/03/2007 07:51:45
 
 
To
29/03/2007 07:30:16
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01209609
Message ID:
01209617
Views:
18
This message has been marked as the solution to the initial question of the thread.
>I have a table as follows:
>
>
>QTY     MAIN     LEN_FT     LEN_IN     WEIGHT      TWEIGHT .......
>1        M        45           0         8580        8580
>8                  2           6           39.3       314.40
>2                  4           5          128.4       256.8
>2        M        30           6         3960        7920
>4                  3           0           50         200
>1        M        45           0         8580        8580
>
>
>
>What I need is one entry for each main, 'M', material that contains the length of the main material but the weight of the main material and the non main material directly following. For example:
>
>
>QTY     MAIN     LEN_FT     LEN_IN     TWEIGHT    ........
>1        M         45          0        9151.20
>2        M         30          6        8120
>1        M         45          0        8580
>
>
>Can someone please provide me with some suggestions on how to best accomplish this?
>

Since the number of records in a group varies and the relationship is based on position rather than data, you can't use a SQL query for this; you'll need Xbase code, along these lines:
nTotal = 0
SCAN
   IF Main = "M"
      * Finish the last record
      REPLACE TWeight WITH m.nTotal

      * Start a new record
      INSERT INTO NewTable (Qty, Main, Len_Ft, Len_In) ;
         VALUES (OldTable.Qty, "M", OldTable.Len_Ft, OldTable.Len_In)
      
      nTotal = OldTable.TWeight
   ELSE
      nTotal = m.nTotal + OldTable.TWeight
   ENDIF
ENDSCAN
Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform