I wrapped the LISTAGG in a CTE, then used CAST to trim the resulting NOTES field.
(see below)
WITH TEMP1 (A6AN8, C5SERK) AS (
SELECT
A6AN8,
C5SERK
FROM
BEHPROD.F0401
JOIN
BEHCOMM.F00163
ON C5WAPP = '*ADDNOTE'
AND C5CKEY = DIGITS(A6AN8)
) ,
TEMP2 ( A6AN8,C5SERK,NOTES ) AS (
SELECT
A6AN8,
C5SERK,
LISTAGG(CAST(TRIM(CYWTXT) AS VARCHAR(32000)),' | ')
WITHIN GROUP (ORDER BY A6AN8,C5SERK)
FROM
TEMP1
JOIN
BEHCOMM.F0016
ON C5SERK = CYSERK
GROUP BY
A6AN8,
C5SERK
) ,
TEMP3 ( SUPPLIER_ID , OUTPUT_TYPE, NOTE_TEXT ) AS (
SELECT
A.A6AN8 AS SUPPLIER_ID ,
'JDENOTE' AS OUTPUT_TYPE ,
CASE
WHEN NOTES IS NOT NULL
THEN CAST(LEFT(NOTES,2000) as char(2000))
ELSE ' '
END AS NOTE_TEXT
FROM BEHPROD.F0401 A
LEFT OUTER JOIN TEMP2 T
ON A.A6AN8 = T.A6AN8
JOIN BEHPROD.F0101
ON A.A6AN8 = ABAN8
WHERE
ABAT1 NOT IN ('X' , 'CL' , 'DLT' )
AND UPPER(ABALPH) not like 'FAMILY OF%'
AND (
A.A6AN8 IN (SELECT XXPYE FROM QGPL.SUPPPYE) OR
A.A6AN8 IN (SELECT XXan8 FROM QGPL.SUPPAN8)
OR A.A6AN8 IN (2524,114261,489678,563330, 661079,729441)
)
-- AND A.A6AN8 NOT IN (4896782524,114261,489678,563330,661079,729441)
ORDER BY A.A6AN8
)
SELECT
CAST(SUPPLIER_ID AS CHAR(25)) AS SUPPLIER_ID , OUTPUT_TYPE, NOTE_TEXT
FROM TEMP3
WHERE NOTE_TEXT <> ' '
Regards,
Steve
-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of David Gibbs via MIDRANGE-L
Sent: Tuesday, December 30, 2025 1:12 PM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Cc: David Gibbs <david@xxxxxxxxxxxx>
Subject: Re: Limiting size limits for LISTAGG function
On Tue, Dec 30, 2025 at 12:05 PM Infodorado InfoDorado via MIDRANGE-L < midrange-l@xxxxxxxxxxxxxxxxxx> wrote:
Greetings fellow humans
I've checked around but can't find an answer to this.
How can you do a limit to the size of a LISTAGG result, say, to a
column width of 48?
Substring?
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.