我有一个包含数据的表格
id parent order tab desc
------------------------------------------------------------------------
1 Null 1 False abcdef
2 Null 2 False efgh
3 1 1 False sadad
4 1 2 False aasd
5 3 1 True qwer
6 3 1 True asdad
7 5 1 False zxzc
8 5 2 False okli此表包含有关具有子部分和选项卡列的所有页面的数据,该列指示它是该页面上的选项卡,而不是新页面
我想生成xml并使用这些数据生成一个breadcrumb,如何使用这些数据来实现呢?
发布于 2010-11-09 04:45:39
对于breadcrumb,您需要使用递归CTE,如下所示:
;with Tree as
(
select CONVERT(varchar(100), id) as Path, id
from Tbl
where Tbl.Parent is null
union all
select Tree.Path + ' > ' + id as Path, id
from Tbl
inner join
Tree
on Tree.id = Tbl.Parent
)
select * from Tree这里的breadcrumb只是每一行的id,但是您可以将它更改为您想要的任何列(也可以在结果集中包含您想要的任何其他列)。
https://stackoverflow.com/questions/4127849
复制相似问题