生成数据库
问题描述:
面包屑我有一个数据表生成数据库
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并使用这些数据生成面包屑,我该如何实现使用这些数据?
答
面包屑,你需要使用递归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
这里的面包屑是每一行的只是ID,但你可以改变它,你想要哪个列(也在你的结果集中包括你想要的其他任何列)。