I am getting data like
Result
------
10
23
21
But i want to get data in the following format.
Result
------
10, 23, 21
How to get that in a Query? Thanks in advance for any help :)
I am getting data like
Result
------
10
23
21
But i want to get data in the following format.
Result
------
10, 23, 21
How to get that in a Query? Thanks in advance for any help :)
Sample code that doesn't use stored procedure :) ...
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
More about it here:
SQL SERVER – Comma Separated Values (CSV) from Table Column
Edit:
For SQL-Server 2000, take a look here:
You can also check out: http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string
In PostgreSQL:
SELECT company_id, array_to_string(array_agg(employee), ',') FROM mytable GROUP BY company_id;