I based this on some example I saw online.

Use it for column text as a CSV header row, combining rows of text into one column like customer comments or multiple email addresses assigned to a customer - typically with a pipe delimiter.
It's such a handy function.

select listagg(cast(column_text as varchar(64)), ' , ')
within group(order by ordinal_position) as coltext
from qsys2.syscolumns
where table_schema = < your lib >
and table_name = < your pf >



-----Original Message-----
From: OpenSource <opensource-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Richard Schoen
Sent: Saturday, December 4, 2021 10:08 AM
To: opensource@xxxxxxxxxxxxxxxxxx
Subject: Re: [IBMiOSS] Beginner Python Question about Db2 to Excel

Hey Roger,

Would love to see a sample of what you're describing.

Regards,
Richard Schoen
Web: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.richardschoen.net%2F&amp;data=04%7C01%7C%7C61a92f819fbb4954ca4308d9b75108df%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637742380953974594%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=DyYNVzxiIIPo6o6zK9bu7UCHRBGbOEQ5CrmJ9igYz40%3D&amp;reserved=0
Email: richard@xxxxxxxxxxxxxxxxx

------------------------------

message: 4
date: Fri, 3 Dec 2021 23:47:45 +0000
from: Roger Harman <roger.harman@xxxxxxxxxxx>
subject: Re: [IBMiOSS] Beginner Python Question about Db2 to Excel

I do this all the time in DB2 SQL but I'm creating CSV's.

I use List_Agg() to get all the data from syscolumns in one CSV row. Our DB is standardized around the TEXT() info not COLHDG() but the concept would be similar.

You'll probably want to be sure to "order by ordinal_position" to get them in the right sequence.

I'll be interested in seeing the Python solution with COLHDG() and formatting them as multi-line headers in Excel.


Roger Harman

COMMON Certified Application Developer - ILE RPG on IBM i on Power

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.