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 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply