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
Solved

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

Posted on 2013-11-12
3
361 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
  • 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

828 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