× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks all...

I need this in two columns (eventually maybe up to 5 columns)... so listagg doesn't seem to do it. Charles Join example also creates a single column.

I used Birgitta's example - this returns the desired output, but took 60 seconds. My sub-select took 31 milliseconds.
The NOTEPDUC file is large file (12m records).

Run SQL Scripts Explain does not recommend any additional indexes. The aggregation and table probe were the big winners.

So I'm wondering if the sub-select is the best approach?

Thx


-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Birgitta Hauser
Sent: Tuesday, March 12, 2024 4:48 PM
To: 'Midrange Systems Technical Discussion' <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: SQL rows to columns

You may try something like this (it is at least one Sub-Select less)

With x as (Select Ucntk, Min(Case When UCq3# = 1 Then UCCMT End) Comment1,
Min(Case When UCq3# = 2 Then UCCMT End) Comment2
from Notepduc
Where UCNOTT = 'C'
and UCSQ3 in (1, 2)
Group By UCNTK
Select Odcom#, Odord#, Odcmt#,
Coalesce(Comment1, '') Comment1, Coalesce(Comment2m '') Comment2
from Oeorlod Left join x on ucntk = Odcmt#

Mit freundlichen Grüßen / Best regards

Birgitta Hauser
Modernization - Education - Consulting on IBM i Database and Software Architect IBM Champion since 2020


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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

This mailing list archive is Copyright 1997-2024 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.