我需要能够检索所有用户以及他们所属的业务单位的默认团队。
除了用于团队和BU的同一名称外,我如何识别业务单位的默认团队。是否有一个标志将其标识为默认团队?
我需要的输出是以下列
这是我的查询。
SELECT dbo_SystemUser.DomainName, (dbo_Team.Name + ' ' + dbo_Team.TeamId)
FROM (dbo_Team INNER JOIN (dbo_TeamMembership INNER JOIN dbo_SystemUser ON dbo_TeamMembership.SystemUserId = dbo_SystemUser.SystemUserId) ON dbo_Team.TeamId = dbo_TeamMembership.TeamId) INNER JOIN dbo_BusinessUnit ON dbo_Team.BusinessUnitId = dbo_BusinessUnit.BusinessUnitId
WHERE dbo_Team.Name = dbo_BusinessUnit.Name
答案 0 :(得分:2)
Team
表格为IsDefault
列TRUE
。
它也包含在FilteredTeam
视图中。
解决OP问题的查询:
-- Pay attention to the FROMs, tables ignore Security Roles.
-- To respect security, query the filtered views
-- (FilteredSystemUser, FilteredTeam, FilteredTeamMembership)
-- On the other hand, querying tables is much faster
SELECT U.DomainName as [Domain Name], T.Name as [Team Name], T.TeamId as [Team ID]
FROM SystemUser U
INNER JOIN TeamMembership TM ON U.SystemUserId = TM.SystemUserId
INNER JOIN Team T ON TM.TeamId = T.TeamId
WHERE T.IsDefault = 1
答案 1 :(得分:1)
这应该这样做。
SELECT FilteredSystemUser.domainname, FilteredTeam.name, FilteredTeam.teamid
FROM FilteredSystemUser
INNER JOIN FilteredBusinessUnit ON FilteredSystemUser.businessunitid = FilteredBusinessUnit.businessunitid
INNER JOIN FilteredTeam ON FilteredTeam.businessunitid = FilteredBusinessUnit.businessunitid
WHERE FilteredTeam.isdefault = 1
您还需要使用Filtered Views.