STRING_AGG SQL 2017 (14) or later

New SQL features are hard to use because it's years before I get customers that have the new version of SQL

But this feature came out in SQL 2017, and it's becoming available.

 

STRING_AGG will turn this

Into this

 

Simple example

SELECT STRING_AGG(RTRIM(itemnmbr),', ')
    FROM SOP10200 l
    WHERE sopnumbe = 'std10119419'

Get holds for a group of orders:

SELECT h.sopnumbe, ho.HoldType
    FROM SOP10100 h
        LEFT JOIN (
            SELECT
                    ho.sopnumbe, ho.soptype,
                    STRING_AGG(RTRIM(ho.PRCHLDID), ',') as HoldType
                FROM sop10104 ho
                WHERE ho.DELETE1 = 0
                GROUP BY ho.SOPNUMBE, ho.soptype
        ) ho ON ho.SOPNUMBE = h.sopnumbe AND ho.soptype = h.SOPTYPE
    WHERE h.SOPNUMBE LIKE 'STD101300%'

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences