Query to get the Department along with their Users (comma seperated)

Amatya
Posted by Amatya under Sql Server category on | Points: 40 | Views : 181
 SELECT 
DISTINCT D.DepartmentName,
(SELECT FirstName +',' FROM [Amatya].[dbo].[tblUsers] WHERE DepartmentId = D.DepartmentId FOR XML PATH(''))
FROM[Amatya].[dbo].[tblDepartments] D


Result Demo:

i.e Software | Amatya,Urvi,Shryansh,Ram,Mayank

Thanks.

Comments or Responses

Login to post response