June 9, 2014 at 8:06 am
Hello all -
This is probably very simple but the solution evades me. I have a single column returned from a select statement. How can I have this returned as a vertical string? I looked into using PIVOT but my scenario seems too simple to use Pivot. I'm not requiring any aggregate functions or anything.
So, I want to turn this:
SELECT CountyNames + ',' FROM Counties
---------------------
County1 ,
County2 ,
County3 ,
..etc
TO:
County1, County2, County3...etc
Please note that the list of rows is unknown. Could be 1. Could be 50.
Thanks in advance!!
June 9, 2014 at 2:00 pm
declare @myCSV varchar(1000)
set @myCSV=''
select @myCSV=@myCSV+','+ name from sys.databases
select substring(@myCSV, 2, len(@myCSV)-1) as myCSV
June 9, 2014 at 2:08 pm
If I understand correctly, this article explains what you need:
http://www.sqlservercentral.com/articles/comma+separated+list/71700/
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy