Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Como obter o valor CSV para o seguinte cenário

select AccountNumber, 
       stuff((select ',' + Product 
                  from YourTable t2 
                  where t2.AccountNumber = t1.AccountNumber 
                  order by Product 
                  for xml path('')),1,1,'') as ProductString
    from YourTable t1
    group by AccountNumber