Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Selecting multiple rows to one string

Posted on 2001-07-27
Medium Priority
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
How can I get oen string 'Microsoft,Oracle,Borland,...'
without using cursors.
Question by:rosmonov
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
LVL 39

Accepted Solution

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

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

select @X
LVL 39

Expert Comment

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)



Expert Comment

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

Expert Comment

ID: 6326465
This seems to have lost my post

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


Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

670 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