Home Forums SQL Server 2005 T-SQL (SS2K5) CONVERT COLUMN VALUES TO COMMA SEPARATED ONE ROW VALUE.. RE: CONVERT COLUMN VALUES TO COMMA SEPARATED ONE ROW VALUE..

  • ;with SampleDataR as

    (

    select *, ROW_NUMBER() over (partition by title, subtitle order by value) rownum

    from test12

    )

    select distinct title, subtitle,(

    select value

    + case when s1.rownum = (select MAX(rownum) from SampleDataR where title = s1.title and subtitle = s1.subtitle)

    then '' else ',' end from SampleDataR s1

    where s1.title = s2.title and s1.subtitle = s2.subtitle

    for xml path(''),type).value('(.)[1]','varchar(max)') csvList

    from SampleDataR s2