码迷,mamicode.com
首页 > 其他好文 > 详细

CTE Tree

时间:2015-02-05 20:35:04      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

;with Tree as
(
 select wjgl_20_col_10 as ID, wjgl_20_col_30 as Name,wjgl_20_col_60 as Parent from wjgl_20
 where WJGL_20_COL_50=1 and (WJGL_20_COL_70 is null or WJGL_20_COL_70=1) and WJGL_20_COL_100=1
)
,CTE as  
(  
-->Begin 一个定位点成员  
 select ID, Name,Parent,cast(‘已发布文件/‘+Name as nvarchar(max)) as TE,0 as Levle from Tree where Parent=‘0‘  
-->End   
union all  
-->Begin一个递归成员  
 select Tree.ID, Tree.Name,Tree.Parent,cast(CTE.TE+‘/‘+Tree.name as nvarchar(MAX)) as TE,Levle+1 as Levle  
        from Tree inner join CTE  
        on Tree.Parent=CTE.ID  
-->End  
)  
select * from CTE order by TE

CTE Tree

标签:

原文地址:http://my.oschina.net/ind/blog/375851

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!