For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string. If I google STRING_AGG, all I see is praise for STRING_AGG but no example of how to handle it prior to SQL 2017. input_string is the character string to be processed. Jeffry Schwartz compares the performance of STRING_AGG in SQL Server 2017 versus the tried and true method of FOR XML PATH for string concatenation: Two different T-SQL methods were used for testing. An expression that specifies the string values to aggregate. Concatenate multiple records in a single field using ABAP CDS Table ... (vnext) In my example, there is a lot of string . Most of the Database Developers require to perform String Aggregation based on different group of records. What is the most flexible way to do a STRING_AGG of SQL in Excel? Alternatives of array_agg() or string_agg() on redshift. LISTAGG aggregate function - IBM The following example will rollup all currency names and separate each using a forward slash. Although this is a primitive example of the power of [code ]STUFF()[/code], I do find that it is used very frequently in this capacity, . Its just that in SQL Server, it was available from 2017 version and on wards where as in Postgres it was available from version 9.0 (released in year 2010). The first GROUP BY will remove duplicates, the second GROUP BY will produce the final result. The FOR XML PATH method has been documented thoroughly over the years in many articles, so these . On production I have SQL Server 2014 running and had to work on alternative for STRING_AGG which is not supported on older version. It was added in SQL Server 2017 (14.x) and later or SQL Azure. STRING_AGG basically groups values of a field based on the values of another field and it separates them via a delimiter i.e. What are some alternatives of STUFF() function in SQL Server? #0415 - SQL Server - Performance Tuning - Use STRING_AGG to generate ... With more and more data being exchanged over APIs, generating comma-separated strings are becoming a much more common requirement. Distinct List in String_Agg - Greg's Ramblings If start_position is negative, zero, or longer than the length of the string, the function will return NULL. If you the list to be in a given order, you would use Within Group. Let's have a closer look at the nested stuff in this query.