Solved

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.

749 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