.net 从数据库生成面包屑
我有一张数据表.net 从数据库生成面包屑,.net,asp.net,sql-server,sql-server-2005,sql-server-2008,.net,Asp.net,Sql Server,Sql Server 2005,Sql Server 2008,我有一张数据表 id parent order tab desc ------------------------------------------------------------------------ 1 Null 1 False abcdef 2 Null 2 False efgh 3 1 1 False sadad
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
此表包含有关包含子节的所有页面的数据,tab列表示它是该页面上的tab,但不是新页面
我想使用此数据生成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
这里的breadcrumb只是每行的id,但是您可以将其更改为您想要的任何列(还可以在结果集中包含您想要的任何其他列)