I have two tables in sql 2012: name and prod with structure:
name: id int increment, name1 nvarchar(50)
id int increment, name1 nvarchar(50)
prod:
try this:
SELECT G.id, G.name1, stuff( (select cast(',' as varchar(10)) + U.product from prod U WHERE U.id_name = G.id order by U.product for xml path('') ), 1, 1, '') AS prod FROM name G ORDER BY G.name1 ASC