开发者

Want to concatenate three - four rows in SQL Server

Example:

Table  
Account id, team_name_product

Initially it is like this:

account id team_n开发者_如何学JAVAame_product
1  MCLO:Wyatt, Gregory (SYM, SER); 
1  MCR2:Garcia, Rebecca (CRE); 
1  MCR1:Gonzalez) 

Across account id, I want to concatenate the 3 rows having different teams with different names of people.

Result should look like this:

Account ID,(MCLO:Wyatt, Gregory (SYM, SER); MCR2:Garcia, Rebecca (CRE); MCR1:Gonzalez)                                      


select Y1.[account id],
       stuff((select ' '+Y2.team_name_product 
              from YourTable as Y2
              where Y1.[account id] = Y2.[account id]
              for xml path(''), type).value('.', 'varchar(max)'), 1, 1, '') as team_name_products
from YourTable as Y1
group by Y1.[account id]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜