Link to home
Start Free TrialLog in
Avatar of JackW9653
JackW9653Flag for United States of America

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JackW9653

ASKER

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
your are welcome