-1

Possible Duplicate:
Concatenate many rows into a single text string?
Simulating group_concat MySQL function in Microsoft SQL Server 2005?

I'm working with MS Sql Server 2008, I have the following table

----------------
Uid | Alias |
--------------- |
1 | Pierre |
1 | Patrick |
1 | Jean |
2 | Alice |
2 | Diana |

and I want to display it in this manner:

------------------------|
Uid | Alias |
------------------------|
1 | Pierre Patrick Jean|
2 | Alice Diana |

Any idea will be appreciate.

Community
  • 1
  • 1
user1805523
  • 179
  • 1
  • 2
  • 12

1 Answers1

1

Please try:

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
TechDo
  • 18,398
  • 3
  • 51
  • 64