Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Convert multiple rows to one row separated by delimiter Expand / Collapse
Author
Message
Posted Monday, June 2, 2014 9:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 11, 2014 7:45 PM
Points: 14, Visits: 36
Hi,

I am running sqlserver 2012.
My output data is like
COL1
aaa
bbb
ccc

Now, i want to convert the output to
aaa;bbb;ccc

How can i do this?
Post #1576626
Posted Monday, June 2, 2014 9:18 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 5:19 PM
Points: 3,374, Visits: 7,303
Read the following article to find out how to do it.
http://www.sqlservercentral.com/articles/comma+separated+list/71700/



Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1576634
Posted Monday, June 2, 2014 9:38 AM This worked for the OP Answer marked as solution


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 2:18 PM
Points: 4,013, Visits: 6,091
create table #TestData (Col1 varchar(20))
insert into #TestData
select 'aaa' union all
select 'bbb' union all
select 'ccc'

select stuff((select ','+Col1
from #TestData
order by col1
for xml path(''))
,1,1,'') as delimitedlist


Edited:

Whups, you were too quick for me Luis. Yes, that article is a better reference.


__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? -- Stephen Stills
Post #1576644
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse