TheLazyPig
Programmer
Is there a LISTAGG code in foxpro9 or any similar process?
Thank you for the response.
Thank you for the response.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Function StringAgg
Lparameters SourceTable, AggregationField, groupby, groupid
Local lcAggString
Try
Select curSringAgg
Catch
Create Cursor curSringAgg (Id Int, aggregation M)
Endtry
Locate For Id = groupid
If Not Found()
Select &AggregationField as cListItem From (SourceTable) Where &groupby = groupid Order by &AggregationField Into Cursor curTemp
Select curTemp
lcAggString= ""
Scan
lcAggString = lcAggString + ","+Transform(cListItem)
Endscan
Use in curTemp
Insert Into curSringAgg Values (groupid, Substr(lcAggString,2))
Endif
Return curSringAgg.aggregation
Endfunc
Open Database (_samples+"Northwind\Northwind.dbc")
Select Orders.OrderID, Cast(StringAgg("OrderDetails","Productid","OrderID", Orders.OrderID) as V(254)) as products from orders ;
Left Join OrderDetails on OrderDetails.orderid = orders.orderid;
Group By 1;
into cursor result
Function StringAgg
Lparameters SourceTable, AggregationField, groupby, groupid
Local lcAggString
Select &AggregationField as cListItem From (SourceTable) Where &groupby = groupid Order by &AggregationField Into Cursor curTemp
Select curTemp
lcAggString= ""
Scan
lcAggString = lcAggString + ","+Transform(cListItem)
Endscan
Use in curTemp
Return Substr(lcAggString,2)
Endfunc
Open Database (_samples+"Northwind\Northwind.dbc")
Select Orders.OrderID, Cast(StringAgg("OrderDetails","Productid","OrderID", Orders.OrderID) as V(254)) as products from orders ;
into cursor result