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: Friday, October 10, 2014 10:21 AM
Points: 16, Visits: 59
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 @ 2:37 PM
Points: 3,910, Visits: 8,875
Read the following article to find out how to do it.
http://www.sqlservercentral.com/articles/comma+separated+list/71700/



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

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


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, August 17, 2014 3:10 PM
Points: 2,787, Visits: 6,098
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