0

I am have a table:

Student| Grade
qwe    | 100
qwe    | 95
qwe    | 90
asd    | 85
asd    | 90
zxc    | 80
zxc    | 75
zxc    | 100

and my Expected output like this, How can I do that?

Student | Grade
qwe     | 100; 95; 90
asd     | 85; 90
zxc     | 80; 75; 100

I tried like this but it is wrong:

SELECT d.Student, d.Grade FROM Data d GROUP BY d.Student

Please, help.

Thanks to everyone. I used this query and it works:

SELECT DISTINCT t1.Student, 
( SELECT t2.Grade+'; ' 
  FROM Data t2 
  WHERE t2.Student = t1.Student 
  FOR XML PATH('') ) Concatenated
FROM Data t1

1 Answers1

0

I copied this from Jpw's link:

SELECT STUFF(
             (SELECT ',' + Column_Name 
              FROM Table_Name as [InteriorQuery]
              FOR XML PATH (''))
             , 1, 1, '')
FROM TABLE_NAME as [ExteriorQuery]

Inside the STUFF, place a where clause, such as

where [InteriorQuery].Student = ExteriorQuery.Student
Arthur D
  • 86
  • 3