Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to write this SQL Statement?
Message
From
03/01/2003 05:23:34
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
02/01/2003 20:08:35
F Bilo
Bilo Office
Fuyang, China
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00737372
Message ID:
00737626
Views:
18
>unfortunately, you is right, my table have a dozen extra fields, then...:(

Fbilo,
As I said wouldn't try to do with SQL directly.
Supposing your fieldname field doesn't contain any value that's illegal for a fieldname and number of distinct fieldnames isn't over 254 (+1 for id - table column limit) :
local ix, oRecord
local array arrFields[1], arrStruc[1]
select distinct fieldname from oldTable into array arrFields
dimension arrStruc[alen(arrFields,1)+1,4]
arrStruc = 0
arrStruc[1,1] = "ID"
arrStruc[1,2] = "I"
arrStruc[1,3] = 4
for ix=1 to alen(arrFields,1)
  arrStruc[ix+1,1] = trim(arrFields[ix])
  arrStruc[ix+1,2] = "C"
  arrStruc[ix+1,3] = 50
endfor
create table newTable from array arrStruc
scatter name oRecord blank
select * from oldTable order by id into cursor crsTemp
scan
 oRecord.id = crsTemp.ID
 scan while ID = oRecord.id
  store FieldValue to ('oRecord.'+fieldname)
 endscan
 skip -1
 select NewTable && VFP8 : insert into NewTable from name oRecord
* Could also use scatter memvar, insert into .. from memvar
 append blank
 gather name oRecord
 scatter name oRecord blank
 select crsTemp
endscan
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform