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 2005 Forums
 Transact-SQL (2005)
 concatenate a field in a slect statement

Author  Topic 

kalwork
Starting Member

5 Posts

Posted - 2008-05-17 : 19:16:56
I have a query that returns multiple results

Select fname from table
returns

fred
joe
dave

What I want to do is have the query return only one result like this
"fred, joe, dave"

Any ideas?

Thanks

Kal

nathans
Aged Yak Warrior

938 Posts

Posted - 2008-05-17 : 20:54:18
check here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53293
and: http://www.sqlteam.com/article/converting-multiple-rows-into-a-csv-string-set-based-method


Nathan Skerl
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-18 : 05:41:05
One method:-

SELECT LEFT(l.list,LEN(l.list)-1)
FROM (SELECT fname + ',' AS [text()]
FROM YourTable
FOR XML PATH(''))l(list)
Go to Top of Page
   

- Advertisement -