Click here to Skip to main content
12,559,389 members (49,942 online)
Rate this:
Please Sign up or sign in to vote.
See more: SQL SQL-Server

Here's a snapshot of the data I have

SubjectID       StudentName
----------      -------------
1               Mary
1               John
1               Sam
2               Alaina
2               Edward

I need to group it as below:

SubjectID       StudentName
----------      -------------
1               Mary, John, Sam
2               Alaina, Edward

Any solutions based on COALESCE? Co-Related Sub Query? or probably even simpler ways?
Posted 6-Feb-12 22:36pm
Updated 6-Feb-12 22:42pm
walterhevedeich 7-Feb-12 4:43am
What have you tried?
Jyothikarthik_N 7-Feb-12 4:46am
I've tried COALESCE:

SELECT @StudName=COALESCE(@StudName+ StudentName) FROM table WHERE
SELECT @StudName

This query simply gives me:
Mary, John, Sam, Alaina, Edward

I'm getting hit at a way to combine the SubjectID with the StudentName.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There's a tip here[^] that could do the trick for you.
Jyothikarthik_N 7-Feb-12 7:20am
That should solve, thanks!
Jörgen Andersson 7-Feb-12 7:28am
You're welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161026.1 | Last Updated 7 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100