Solved

Multiple Values in SQL table returned in single column separated by commas

Posted on 2013-11-12
3
370 Views
Last Modified: 2013-11-13
Hi Experts,

I have a SQL Server table of short (nvarchar 75) answers filed using a code to group them by. I'm wanting to run a query that will return all answers given for a specific code separated by a comma.

For example:
100    Apple
100    Orange
100    Pear
200    Grape
200    Tangerine

Query returns for group 100:
Apple, Orange, Pear

I've used FOR XML PATH in the past but was hoping to find a different approach. Thanks,

JackW9653
0
Comment
Question by:JackW9653
[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
3 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 39642620
Hi
Using COALESCE . Refer this example
stackoverflow.com/questions/655197/converting-rows-into-columns-in-t-sql-sql-server-2005

Raj
0
 

Author Closing Comment

by:JackW9653
ID: 39643077
Hi Raj,

Thanks for your reply. I used COALESCE and was getting extra characters between text and comma, then I added a RTRIM statement and the world was right again.

JackW9653
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 39643887
your are welcome
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

729 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