Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transpose data best practice
Message
From
24/08/2002 06:28:34
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
23/08/2002 14:10:12
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00693069
Message ID:
00693259
Views:
21
This message has been marked as the solution to the initial question of the thread.
>Hi all,
>
>Is there a best practice to transpose data in VFP based on a column or columns
>
>
>Example: Transpose data by F4, then F1
>Table1
>F1   F2   F3  F4
>AAA   1    1  8/22/02
>AAA   2    1  8/22/02
>AAA   3    1  8/22/02
>BBB   1    1  8/22/02
>BBB   2    1  8/23/02
>CCC   3    1  8/23/02
>
>Result:
>
>F4       F2 F3AAA F3BBB F3CCC
>8/22/02   1     1     1     -
>8/22/02   2     1     1     -
>8/22/02   3     1     -     -
>8/23/02   2     -     1     -
>8/23/02   3     -     -     1
>
Ramil,
There vfpxtab.prg (_genxtab). However depending on your needs it might be much more effective to create your own version. Your data sounds like one that vfpxtab wouldn't handle. ie (assuming your result set have a typo for 'BBB' series :
select distinct f1 from myTable into array arrExtraCols 
IF _Tally = 0
	MESSAGEBOX('No rows to process')
	RETURN
endif
&& Assuming 'F3'+F1 values qualify to be a fieldname
lcExtra = ''
for ix=1 to alen(arrExtraCols,1)
  lcExtra = lcExtra + ',0x00000000 as F3'+trim(arrExtraCols[ix,1])
endfor
select distinct f4,f2 &lcExtra from myTable into cursor xTabbed readwrite 
scan
 scatter name oRecord
 select myTable
 for ix=3 to fcount('xTabbed')
   locate for f4 = oRecord.f4 and f2 = oRecord.f2 and ;
       upper(f1) = substr(field(ix,'xTabbed'),3)
   store f3 to ('oRecord.'+field(ix,'xTabbed'))
 endfor
 select xTabbed
 gather name oRecord
ENDSCAN
browse
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