将单元格连接在一起以缩短sql的结果

时间:2016-08-03 18:01:32

标签: tsql select concatenation

假设我在t-sql中的select语句返回

John Smith | Chicago | a  
John Smith | Chicago | f  
John Smith | Chicago | j  
Josh Dude  | Houston | p  
Josh Dude  | Houston | s  

我希望它返回

John Smith | Chicago | a, f, j  
Josh Dude  | Houston | p, s

我该怎么做?

1 个答案:

答案 0 :(得分:0)

文章的前半部分T-SQL: Normalized data to a single comma delineated string and back是关于如何使用STUFF和FOR XML PATH语句的代码和图像密集型教程,它采用规范化集合并将一列转换为单个逗号分隔值。

祝你好运。