all groups > sql server (alternate) > july 2003 >
You're in the

sql server (alternate)

group:

SQL statement: Is this Possible?


SQL statement: Is this Possible? arockwel NO[at]SPAM yahoo.com
7/14/2003 1:22:55 PM
sql server (alternate):
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


Re: SQL statement: Is this Possible? Erland Sommarskog
7/14/2003 9:26:26 PM
Aaron (arockwel@yahoo.com) writes:
[quoted text, click to view]

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, sommar@algonet.se

Books Online for SQL Server SP3 at
Re: SQL statement: Is this Possible? Wangkhar NO[at]SPAM yahoo.com
7/15/2003 1:30:49 AM
AddThis Social Bookmark Button