ListAgg and Split – Grouping, Aggregating and Dividing Again

Almost everybody working with SQL knows the GROUP BY specification for accumulating identical information. Those queries are quite often combined with aggregate functions such as SUM() or AVG().
 
With the multi-dimensional grouping it is possible to also add all kinds of sub-totals as well as a grand total to the queries.
In composition with CASE clauses it is possible to accumulate information and return the data in different columns, for example monthly or quarterly sales per customer. Pivot tables can be easily created … as long as the number of output columns is fixed.
Sometimes, however, we have to accumulate information that is located in multiple rows in a single row, for example all items in an order.
 
Unfortunately, the number of output columns (i.e. Items) may differ. However, with the LISTAGG aggregate function a string containing the different information separated by a comma (or any individual separation string) can be built.
 
As far as good … but how to split a string with multiple information separated by a comma or any other individual separation string? No problem with the SPLIT service! … in composition with other services even *.csv files located in the IFS can be decomposed

Birgitta Hauser

Independent Consultant

Birgitta Hauser graduated with a business economics diploma and started programming on the AS/400 in 1992. She is an experienced RPG programmer as well as a database and software engineer, focusing on IBM i application and database modernization. Today, she is an independent consultant on application and database modernization on IBM i and Db2 for i. 

Birgitta also works in education as a trainer for RPG and SQL developers. Since 2002, she has been a frequent speaker at COMMON user groups meetings and other IBM i and Power conferences in Germany, other European countries, the United States, and Canada. In addition, she is co-author of two IBM Redbooks and has also authored several articles and papers focusing on RPG and SQL for the ITP Verlag (a German publisher), IT Jungle Guru, and IBM DeveloperWorks. 

She received the John Earl Speaker Scholarship Award in 2015, the Al Barsa Memorial Scholarship Award in 2018, and was named an IBM Champion in 2021.


Key:

Complete
Failed
Available
Locked
Video
Open to view video.
Open to view video.