Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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