• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

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.
0
rosmonov
Asked:
rosmonov
  • 2
1 Solution
 
appariCommented:
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now