Several DB-Engines support this directly with the Group_Concat-
Aggregate-Function (MySQL and SQLite for example)...
In case your Data is hosted in SQLite (or was temporarily put into an
SQLite InMemory-DB) you can do the following:
(Into an empty VB-Form with an MSHFlexGrid1 - and a reference to vbRichClient5)
Producing this:Code:Option Explicit Private Sub Form_Load() With New_c.Connection(, DBCreateInMemory) .Execute "Create Table T(Col1 Text, Col2 Integer)" .Execute "Insert Into T Values('Danny', 1)" .Execute "Insert Into T Values('Danny', 2)" .Execute "Insert Into T Values('Danny', 3)" .Execute "Insert Into T Values('Eric', 7)" .Execute "Insert Into T Values('Eric', 14)" .Execute "Insert Into T Values('Danny',20)" Dim SQL As String SQL = "Select Col1, Group_Concat(Col2) As Col2 From T Group By Col1" Set MSHFlexGrid1.DataSource = .OpenRecordset(SQL).DataSource End With End Sub
Group_Concat has a second (optional) argument, where you can place a String
which is then used as the delimiter for the concat besides the comma) -
e.g. for a SemiColon followed by a SpaceChar:
Group_Concat(Col2, '; ')
Olaf





Reply With Quote
