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 2008 Forums
 Other SQL Server 2008 Topics
 pivot table in sql

Author  Topic 

nord
Posting Yak Master

126 Posts

Posted - 2013-12-12 : 12:10:41
Hi all,
I have table
size_cd size_descr size num
1 01 2
1 02 3
1 02 15
2 03 1
2 04 7
2 05 11

I would like reseive

size_cd
1 2,3,15
2 1,7,11


Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-12 : 13:22:18
[code]
SELECT size_cd,
STUFF ((SELECT ',' + CAST([size num] AS varchar(5)) FROM table WHERE size_cd = t.size_cd ORDER BY [size num] FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT size_cd FROM table)t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -