Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. DECLARE @Test TABLE
  2. (
  3. Course VARCHAR(10),
  4. Student VARCHAR(10)
  5. )
  6.  
  7. INSERT @Test
  8. (Course,
  9. Student)
  10. VALUES ('A1',
  11. 'S1'),
  12. ('A1',
  13. 'S2'),
  14. ('A1',
  15. 'S3'),
  16. ('A2',
  17. 'S4'),
  18. ('A2',
  19. 'S5')
  20.  
  21. SELECT DISTINCT Course,
  22. Stuff((SELECT ',' + Student
  23. FROM @Test T1
  24. WHERE T1.Course = T2.Course
  25. FOR XML PATH('')), 1, 1, '')
  26. FROM @Test T2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement