请查看我的查询
select tms.TeamName,
(select loc.LocID from Locations loc, Users usr where loc.UserID = usr.UserID and usr.TeamID = tms.TeamID)
from Teams tms
在这种情况下,LocID返回多个值。我希望它以逗号分隔值的单列形式出现。我该怎么办?
提前致谢 - Manoj
答案 0 :(得分:2)
select
tms.TeamName,
stuff(
(select ','+cast(loc.LocID as varchar(10))
from Locations as loc
inner join Users as usr
on loc.UserID = usr.UserID
where usr.TeamID = tms.TeamID
for xml path('')), 1, 1, '')
from Teams as tms