Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help me Query

Author  Topic 

niyaz4872
Starting Member

41 Posts

Posted - 2011-10-08 : 04:39:03
following is my table structure

id Desc
1 a
1 b
2 c
2 d
2 e

following is sample results i wan't

id Desc
1 a,b
2 c,d,e

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-08 : 04:43:25
[code]
SELECT id,
STUFF((SELECT ',' + [Desc] FROM yourtable WHERE id = t.id ORDER BY [Desc] ASC FOR XML PATH('')),1,1,'') AS [Desc]
FROM (SELECT DISTINCT id FROM yourtable)t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

niyaz4872
Starting Member

41 Posts

Posted - 2011-10-08 : 05:00:39
tnx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-08 : 05:03:35
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -