摘要: with CTE as
(
-->Begin 一个定位点成员
select ID, Name,Parent,cast(Name as nvarchar(max)) as TE,
ROW_NUMBER()over(order by getdate()) as OrderID
--最关键是上面这个字段,要获取排序字段,按字符串来排序。
--其中窗口函数必须要使用order by,但是不能用整型,那就用时间吧
from Tree where Parent is null
-->End
union all
-->Begin一个递归成员
select Tree.ID, Tree.Name,Tree.Parent,cast(replicate(' ',len(CTE.TE))+'|_'+Tree.name as nvarchar(MAX)) as TE,
<
阅读全文