Solved

Selecting multiple rows to one string

Posted on 2001-07-27
4
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

630 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