Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consolidating multiple rows to a single row

Is it possible to join multiple row values to a single row? The stored procedure from where I acquire the data that I use return multiple, almost identical rows except that the category-column dfferentiates for products that have been assigned multiple categories. I would like to consolidate these categories to one column, separated by new lines. Example data:

Name        Article number   Sales    Sales Category
------------------------------------------------
Product 1   2059102-1        20520    Retailer 1
------------------------------------------------
Product 1   2059102-1        20520    Retailer 2
------------------------------------------------
Product 1   2059102-1        20520    Retailer 3
------------------------------------------------
Product 2   2059102-2        2050     Retailer 1
------------------------------------------------
Product 2   2059102-2        5302     Retailer 3

Desired result:

Name        Article number   Sales    Sales Category
------------------------------------------------
Product 1   2059102-1        20520    Retailer 1
                                      Retailer 2
                                      Retailer 3
------------------------------------------------
Product 2   2059102-2        2050     Retailer 1
                                      Retailer 3

Thank you!

like image 660
Leonard Avatar asked Apr 08 '26 16:04

Leonard


1 Answers

Create an RDL table and setup a Grouping on the Detail section of the table with two grouping expressions (so you have a single Grouping in the Table Details, but with multiple grouping expressions). The grouping expressions should be one for each of the fields: Name, Article number.

Then put a column in the RDL table for each field (Name, Article number, Sales, Sales Category). The trick is putting a List control in the Sales Category cell. In the list add a textbox for the "Sales Category" field and I think you'll get the result you want.

There is also some nasty SQL tricks for "row concatenation", but that is not very maintainable IMHO.

like image 95
Scott Willeke Avatar answered Apr 13 '26 01:04

Scott Willeke