How to turn one column of a table into a csv string in SQL Server without using a cursor

前端 未结 5 1689
灰色年华
灰色年华 2020-12-14 18:02

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 (n

5条回答
  •  情话喂你
    2020-12-14 18:25

    I've had problems with the method discussed in the suggested answer. I took the code from SQLAuthority. But this works every time if you have problem suggested solution

    SELECT SUBSTRING(
    (SELECT ',' + s.ColumnName
    FROM dbo.table s
    ORDER BY s.ColumnName
    FOR XML PATH('')),2,200000) AS CSV
    GO
    

提交回复
热议问题