Solved

Selecting multiple rows to one string

Posted on 2001-07-27
4
216 Views
Last Modified: 2012-05-04
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
Comment
Question by:rosmonov
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
appari earned 100 total points
ID: 6326264
try this
declare @X as varchar(2000)

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

select @X
0
 
LVL 39

Expert Comment

by:appari
ID: 6326265
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
 
LVL 3

Expert Comment

by:ibro
ID: 6326282
appari,
 your last line should be
 select substring(@X, 2, len(@X)-1)
0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6326465
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now