Hi!
It could be done, but with certain conditions and with use of custom function (UDF) in the SQL Select statement (and a lot of experimenting). So I would suggest to do what Sergey told, unless you have time to play with this. In addition, cannot be sure that this will work by the same way in further versions of VFP.
The condition is that records for each group are selected at once in the table scanning order, and no record from another group between records of one group. You can reach this 2 ways. First is to sort table (index will not help). Second way is select all groups first into the temporary cursor, than select details by joining the source table. During joining process VFP will scan groups table and all records for each group will be joined at once. In other words:
SELECT code from MyTable group by code into cursor Tmp
selelct t.code, max(MyFunc(s.name,t.code)) as TXTSUM ;
from force Tmp t ;
inner join MyTable s on t.code = s.code
group by t.code
For sorting just use SORT VFP command.
MyFunc:
public LastRecNo, TXTSum, LastCode
LastRecNo =0
LastCode = 0
TXTSum = ''
...
procedure MyFunc
lparameters cName, nCode
if recno()<>LastRecNo
if nCode=LastCode
TXTSum = TXTSum+cName
else
TXTSum = cName
LastCode = nCode
endif
LastRecNo = recno()
endif
endproc
>It cannot be done with sql select in VFP but you can do it in the code
>
>SELECT 0
>CREATE CURSOR Mycursor ( Name C(60), code C(1))
>
>SELECT Mytable
>SET ORDER TO code
>LOCATE
>lcCode = code
>lcName = Trim(Name)
>DO WHILE NOT EOF()
> SKIP
> SCAN WHILE code = lcCode
> lcName = lcName + ", " + Trim(Name)
> ENDSCAN
> INSERT INTO Mycursor VALUES (lcName, lcCode)
> lcCode = code
> lcName = Trim(Name)
>ENDDO
>
>>I have a table:
>>
>>Name code
>>text1 2
>>text2 2
>>text3 2
>>text4 3
>>text5 3
>>
>>I want to create a cursor gruped by code w/ concatenated Name field:
>>
>>Cursor1
>>Name code
>>Text1, Text2, Text3 2
>>Text4, Text5 3
>>
>>but I don't know how:
>>
>>SELECT ???? AS Name, Code FROM MyTable GROUPED BY MyTable.Code INTO CURSOR Cursor1.
>>
>>
>>TIA
>>
>>
>>Boris
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.comICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs
It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.