I want to return the results of select Column from Table
into a comma separated string using SQL Server.
The column in question is rather large (nvarchar(2000)
) so the solution has to be able to handle very large result values.
In SQL Server, you can select COLUMN_NAME from INFORMATION_SCHEMA. COLUMNS .
STRING_AGG was added in sql 2017
https://docs.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql?view=sql-server-2017
SELECT STRING_AGG (ColumnName, ',') AS csv FROM TableName GROUP BY ColumnName2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With