Aaron (ar******@yahoo.com) writes:
I need a SQL statement to take data that would normally look like this
in a result set (SELECT ID, Name FROM Employee):
ID Name
-- -------
1 Aaron
2 Mike
3 Eric
To look like this, in one row and column with commas separating each
Name:
Names
-------------------
Aaron, Mike, Eric
Any examples of how this might be accomplished? Thanks.
This is one of the few cases where you need to run a cursor (or some
other iterative scheme) to achieve the result. You can do:
SELECT @var = CASE @var IS NULL
THEN ''
ELSE @var + ', '
END + Name
FROM tbl
and you may get the desired result, but the actual result of such a query
is undefined, so you may get something else as well.
--
Erland Sommarskog, SQL Server MVP,
so****@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp