sql2005的一个递归应用
with ColumnCTE ( Organizationid)
as
(select Organizationid from BasOrganization where Organizationid = '0cc7188e-fd61-410c-82d3-f02a4acf78df'
union all select tt.Organizationid from BasOrganization tt join ColumnCTE cte on tt.parentid = cte.Organizationid
)
select emsPort.PortID from ColumnCTE left outer join emsPort on emsPort.PortRelatedOrgID
= Organizationid option(maxrecursion 0)
as
(select Organizationid from BasOrganization where Organizationid = '0cc7188e-fd61-410c-82d3-f02a4acf78df'
union all select tt.Organizationid from BasOrganization tt join ColumnCTE cte on tt.parentid = cte.Organizationid
)
select emsPort.PortID from ColumnCTE left outer join emsPort on emsPort.PortRelatedOrgID
= Organizationid option(maxrecursion 0)