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
 Transact-SQL (2008)
 delimited list and select

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2012-09-05 : 11:37:53
i have table like this :
1,a@b.com
1,adf@b.com
1,adf@bdfgdfg.com
2,dfg@sdf.com

and i want to get :
1,"a@b.com,adf@b.com,adf@bdfgdfg.com"
2,dfg@sdf.com

how do i do this?
10X:)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-05 : 20:51:43
[code]
SELECT id,
STUFF((SELECT ',' + email FROM table WHERE id = t.id FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT id FROM Table)t
[/code]

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

Go to Top of Page
   

- Advertisement -