【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《SQLSERVER:利用CTE循环根据父节点取子节点》,欢迎阅读!
with t as (
SELECT [OrganiseCode],[ParentOrganiseCode] FROM [HSE_Analysis].[dbo].[Dim_Organise] whereOrganiseCode=200100 UNION ALL
SELECT a.[OrganiseCode],a.[ParentOrganiseCode] FROM [HSE_Analysis].[dbo].[Dim_Organise] a INNER JOIN t
ON t.[OrganiseCode] = a.[ParentOrganiseCode] )
SELECT t.OrganiseCode,a.OrganiseName,t.ParentOrganiseCode,b.OrganiseName FROM T left join [HSE_Analysis].[dbo].[Dim_Organise] a ont.OrganiseCode = a.OrganiseId
left join [HSE_Analysis].[dbo].[Dim_Organise] b ont.ParentOrganiseCode = b.OrganiseId
本文来源:https://www.wddqxz.cn/9b3c151ca1c7aa00b42acb12.html