Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create spreadsheet from normalized data
Message
From
09/11/2001 11:41:45
 
 
To
09/11/2001 10:33:45
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00579569
Message ID:
00579706
Views:
28
This message has been marked as a message which has helped to the initial question of the thread.
>>Hi,
>>
>>Can you use sql to transform a dbf table with fields like "code" and "Value" so I get each "code" as a column?
>>
>>Transform records like
>>A1 123
>>A2 234
>>A3 345
>>
>>to
>>
>> A1 A2 A3
>>123 234 345
>
>
>Einar --
>
>Assuming that the Code is 5 characters wide:
>
I wanted to clean this up a bit. <g>
Jay
llOK = .T.

*  Pre -- ensure that cCodes are unique or else you'll get an error
*  creating the table.

SELECT cCode FROM mySourceTable GROUP BY cCode HAVING COUNT (cCode) > 1
llOK = (_TALLY = 0)

IF llOK
*   Generate a file skeleton for the new table.
   SELECT cCode, "C" AS cFieldType, 5 AS nFieldLen, 0 AS nFieldPrec ;
      FROM mySourceTable ;
      INTO ARRAY lamyFileStructureArray
   llOK = BETWEEN (ALEN (lamyFileStructureTable, 1), 1, 255)
ENDIF
*   Create the new table
IF llOK
   CREATE TABLE MyNewTable FROM lamyFileStructureArray
   SELECT MyNewTable
   APPEND BLANK       &&  Add the one new record needed for the new structure.

*   Store the old values into the proper place in the new table.
   X = 1
   SELECT mySourceTable
   SCAN
      lcFieldName =  "MyNewTable." + ALLTRIM (FIELD (X))
      REPLACE (lcFieldName) WITH mySourceTable.cValue IN MyNewTable
      X = X + 1
   ENDSCAN
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform