top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can we get comma separated values from a column in a table

+4 votes
471 views
How can we get comma separated values from a column in a table
posted Feb 18, 2014 by Neeraj Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

I hope you are looking for the comma separated value from a single column....
Check the following code, returns the comma separated names ....

USE AdventureWorks
GO
-- Check Table Column
SELECT Name
FROM HumanResources.Shift
GO
-- Get CSV values
SELECT SUBSTRING(
(SELECT ',' + s.Name
FROM HumanResources.Shift s
ORDER BY s.Name
FOR XML PATH('')),2,200000) AS CSV
GO

Source: http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/

answer Feb 19, 2014 by Meenal Mishra
...