Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Merge many rows into one row
Message
 
To
11/10/2006 07:14:07
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01161133
Message ID:
01161450
Views:
17
Quite some time ago I ran into this problem. Thanks to the miracle of ZIP files I had this snippet lying around:

* create the test data
CLEAR all
CREATE CURSOR 'Table_A' ( ID_A I(9), Name C(32))
CREATE CURSOR 'Table_B' (ID_B I(9), ID_A I(9), Phone C(14))
INSERT INTO 'Table_A' ( ID_A, Name ) VALUES ( 1, 'Jenny' )
INSERT INTO 'Table_A' ( ID_A, Name ) VALUES ( 666, 'Damien' )
INSERT INTO 'Table_A' ( ID_A, Name ) VALUES ( 2, 'Bubba' )
INSERT INTO 'Table_B' ( ID_A, ID_B, Phone ) VALUES ( 1, 445445, '(915) 867-5309' )
INSERT INTO 'Table_B' ( ID_A, ID_B, Phone ) VALUES ( 666, 333333, '(212) 666-6666' )
INSERT INTO 'Table_B' ( ID_A, ID_B, Phone ) VALUES ( 2, 445445, '(404) 127-5490' )
INSERT INTO 'Table_B' ( ID_A, ID_B, Phone ) VALUES ( 1, 777777, '(915) 867-6244' )
INSERT INTO 'Table_B' ( ID_A, ID_B, Phone ) VALUES ( 1, 445445, '(915) 867-5300' )
SELECT Table_A.Name, Table_A.ID_A, Table_B.ID_B, Table_B.Phone ;
from 'Table_A' JOIN 'Table_B' ON Table_B.ID_A = Table_A.ID_A ;
ORDER BY name ;
into cursor 'fred'

* perform an aggregate "collection"
Select 'fred'
STORE 0 TO oldid
STORE "" TO daname,zan
SCAN
IF id_a # oldid
DO doprint WITH daname
zan = phone + " "
oldid = id_a
daname = name
ELSE
zan = zan + phone + " "
ENDIF
ENDSCAN
DO doprint WITH daname

PROCEDURE doprint
LPARAMETERS thename
IF LEN(thename)>0
? ALLTRIM(thename)
?? oldid at 10
?? zan at 25
ENDIF
ENDPROC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform