Department表
Employee表
查询结果:
查询每个部门的人员名称
dbo.View_1:
SELECT dbo.Department.DepName, dbo.Employee.EmpName
FROM dbo.Department INNER JOIN
dbo.Employee ON dbo.Department.DepID = dbo.Employee.DepID
查询:
select DepName,STUFF((select ‘,‘+ EmpName from dbo.View_1 where dbo.View_1.DepName=b.DepName for xml path(‘‘)),1,1,‘‘)as name
from dbo.View_1 as b group by DepName
时间: 2024-10-10 19:47:34