Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Concatenating strings w/ SQL SELECT
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00539337
Message ID:
00539385
Vues:
22
I'm not sure that your solution will work. The recno() function in Myfunction returns record number from the current work area and we have no idea what current work area is or could be.

>
>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:
>
>
>* initialize these variables before query
>public LastRecNo, TXTSum, LastCode
>LastRecNo =0
>LastCode = 0
>TXTSum = ''
>...
>procedure MyFunc
>lparameters cName, nCode
>if recno()<>LastRecNo && this is needed because for first record(s) function called twice
>                      && not sure how it will work here, maybe you will require to use alias name
>                      && for recno
>   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
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform