WITH ctetest(AgencyID,ParentAgencyID,level)AS
(
SELECT AgencyID,ParentAgencyID,0 level FROM dbo.Web_Agency WHERE AgencyID=1
UNION ALL
SELECT a.AgencyID,a.ParentAgencyID,b.level+1 FROM dbo.Web_Agency a,ctetest b WHERE a.ParentAgencyID=b.AgencyID
)
SELECT DISTINCT u.UserID FROM ctetest c INNER JOIN dbo.TUsers u ON c.AgencyID=u.AgencyID

posted on 2016-01-18 09:37  亚洲DotNet首席技师  阅读(158)  评论(0编辑  收藏  举报