How to convert a table column in comma separated values (CSV)
To convert a table column in comma separated values (CSV), I use the following snippet:
DECLARE @tableTABLE
(
Id INT
)
INSERTINTO @tableVALUES (1),(5),(88), (99)
SELECTSUBSTRING(
(
SELECT',' + CAST(Id ASVARCHAR(200))
FROM @tableFOR XML PATH('')
)
,2,2000) AS VAL
No comments:
Post a Comment