There isn't a good way to do this, I'm afraid. This is really a presentation issue, and is more efficiently handled in client code. You could write a solution using a cursor, but since I abhor cursors, that'll be left as an exercise to the reader

.
That having been said, there is sort of a way. I believe this is officially considered undocumented behavior in SQL Server, so you'll have to eat this message after you read it :D.
The TSQL code:
Code:
DECLARE @sa varchar(1000)
SELECT @Sa=@Sa + language + ','
FROM books
WHERE title='The Illiad';
will return the string 'Greek, English, French,'. Or maybe the values in some other order, depending on the phases of the moon and the whims of the optimizer. And that's the reason its undocumented: there is no good way to influence the order of the rows returned while a query is being processed.
Note also that the above technique will only do one 'title' at a time.
In SQL Server 2000 you can define a user-defined function to return the aggregate. If you do this, you can invoke the function for each title:
Code:
CREATE FUNCTION CSVLanguage (@Title as varchar(50))
RETURNS varchar(1000)
AS
BEGIN
DECLARE @Sa varchar(1000)
SELECT @Sa=@Sa + language + ','
FROM books
WHERE title=@Title
RETURN (@Sa)
END
Then invoke the user defined function in your query, as e.g.:
Code:
SELECT title, CSVLanguage(title)
FROM Books
GROUP BY Title;
and this will sort of work, with the same caveat about the 'language' order and the additional warning that there is an inherent limit to the number of languages which can be concatenated together.
If you don't like the trailing comma, I think replacing the
Code:
SELECT @Sa=@Sa + language + ','
line with
Code:
SELECT @Sa=COALESCE(@sa + ',','') + language
will "work". (I put "work" in quotations because I think it is arguable that this trick "works" at all, given that its output is undeterministic (nondeterministic? - whatever)).
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com