Supponendo che i tuoi dati siano in aTable:
create FUNCTION toCSV (@id int)
RETURNS varchar(100)
AS
BEGIN
DECLARE @List varchar(100)
SELECT @List = COALESCE(@List + ', ', '') +
CAST(name AS varchar(10))
FROM aTable
WHERE ID = @id
RETURN(@list)
END;
go
Quindi:
seleziona id distinto, dbo.toCSV(id) da aTable