Using the chr(10) character in a string_agg function will put the aggregated values on separate lines within one cell when exported to Excel. This can be useful to make the output more readable on the report.

Note: Excel has a cell height maximum of 409 pixels. Some aggregated values, such as holdings statements, will easily break that limit, so will be truncated on the spreadsheet.


Example: aggregate the instance_contributors so they appear on separate lines in one cell:


SELECT

ii.title,

ii.hrid AS instance_hrid,

COUNT (DISTINCT ic.contributor_name) as count_of_contributors,

STRING_AGG (distinct ic.contributor_name, chr(10)) AS contributors


FROM inventory_instances AS ii

INNER JOIN folio_reporting.instance_contributors AS ic

ON ii.id = ic.instance_id


WHERE ii.title LIKE 'Apples%'

GROUP BY ii.title, ii.hrid


HAVING COUNT (DISTINCT ic.contributor_name) > 1

LIMIT 100

;


How it looks in Excel:


  • No labels