Click here to Skip to main content
Rate this: bad
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 23:36pm
Edited 6-Feb-12 23:42pm
walterhevedeich at 7-Feb-12 4:43am
What have you tried?
Jyothikarthik_N at 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 at 7-Feb-12 7:20am
That should solve, thanks!
Jörgen Andersson at 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)

Advertise | Privacy | Mobile
Web04 | 2.8.150326.1 | Last Updated 7 Feb 2012
Copyright © CodeProject, 1999-2015
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