In the earlier post we have seen use of xml path to get comma separated result. This post describes how to get comma separated value from a result set or a table data.
Create Table With Following Script.
Create Table CSData
Id Int Identity(1,1),
Insert Into CSData(DepartmentName) Values('IT'),('FINANCE'),('MEDICAL'),('TRANSPORT'),('TALENT TRANSFORMATION'),('IMG')
You have following data.
Now we need comma separated departmentnames.
So its quite easy to have comma separated list. I have used stuff to removed first comma from the result.