标签:
with Test_Recursion(Id,ParentId)
AS
(
select Id,ParentId from [V_KPI_DetailsActivities] where ParentId = 4 --没有引用CTE自身必须放在第一个递归行之上
union all --没有引用CTE自身的语句和第一个递归行之间必须用UNION ALL
select a.Id,a.ParentId from [V_KPI_DetailsActivities] as a join Test_Recursion as b on a.parentid=b.id--递归行
)
select * from Test_Recursion
标签:
原文地址:http://www.cnblogs.com/szlixin/p/4212761.html