可能重复:
Concatenate many rows into a single text string?
Simulating group_concat MySQL function in Microsoft SQL Server 2005?
我正在使用MS Sql Server 2008, 我有下表
----------------
Uid | Alias |
--------------- |
1 | Pierre |
1 | Patrick |
1 | Jean |
2 | Alice |
2 | Diana |
我希望以这种方式显示它:
------------------------|
Uid | Alias |
------------------------|
1 | Pierre Patrick Jean|
2 | Alice Diana |
任何想法都会受到欢迎。
答案 0 :(得分:1)
请尝试:
select b.Uid,
(select a.Alias +' ' from TableName a WHERE a.Uid=b.Uid group by a.Alias FOR XML PATH(''))as Names
from TableName b
group by b.Uid