Concatenating all the values in a column group by another column

  • I have the following data

    TeacherIdStudentid

    11111

    21112

    11113

    21114

    11115

    11116

    11117

    11118

    21119

    31110

    31120

    31121

    21122

    21123

    11124

    11125

    I need a result set like the following with the above data

    teacherIdStudentId

    11111,1113,1115,1116,1117,1118,1124,1125

    21112,1114,1119,1122,1123

    31110,1120,1121

    I need to concatenate all the student Ids of each teacher and should store in a single column for each teacher.

    How can I do this?

  • Check the following article: http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    It explains how to solve your problem.

    If you have any specific questions, feel free to ask.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks for quick help. It worked perfectly.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply