Question

  Asked: Apr 23 2008   7:39 PM GMT
  Asked by: Mgemmill


String Aggregate Function


AS/400, DB2/400, SQL, AS/400 DB2

I need a report that provides an aggregate of a string column - in this case a concatenation of the values in a comma separated string. There is no such DB2 aggregate function that does this. A stored procedure (or possibly a customer aggregate function?) seems the only likely way to accomplish this and my procedure writing skills are rather basic. Essentially, I need to loop through a cursor and concatenate the values and return the data. Given this data:

'abc123', 'one'
'abc123', 'two'
'def456', 'one'
'def456', 'two'

I want to return it as:

'abc123', 'one,two'
'def456', 'one,two'

Any suggestions would be much appreciated. Thanks.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


Start this Answer and Earn your Knowledge Points!

By clicking "Create Answer", you can write the answer to this question that can be improved upon by your peers using the Answer Wiki.

Browse more Questions and Answers on AS/400 and Development.

Looking for relevant AS/400 Whitepapers? Visit the Search400.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register