Selecting multiple rows to one string

Does someone know how to select multiple rows to one string without using cursors.
I mean for example I have
Title
---------
'Microfost'
'Oracle'
'Borland'
...
How can I get oen string 'Microsoft,Oracle,Borland,...'
without using cursors.
rosmonovAsked:
Who is Participating?
 
appariConnect With a Mentor Commented:
try this
declare @X as varchar(2000)

select @X = ' '
Select @X = @X + ',' +  au_lname from authors

select @X
0
 
appariCommented:
sorry this one is proper.
earlier one gives a comma at the beginning

declare @X as varchar(2000)

select @X = ''
select @X = @X + ',' +  au_lname from authors

select substring(@X,2,1999)

RAO

0
 
ibroCommented:
appari,
 your last line should be
 select substring(@X, 2, len(@X)-1)
0
 
nigelrivettCommented:
This seems to have lost my post

declare @X as varchar(2000)
Select @X = coalesce(@X+',','') +  au_lname from authors
select @X

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.