NodeId       int       菜单节点 id 
DisplayName  varchar   菜单名称 
DisplayOrder int      菜单显示顺序 
ParentNodeId int      父节点 id 
这个表结构中怎么查询父节点和子节点  然后在 accordion中显示啊

解决方案 »

  1.   


    --这就是个递归查询,得到FileID=1的所有子节点
    declare @T1 table (FileID int,ParentFileID int,Path varchar(10))
    insert into @T1
    select 1,0,',-1,' union all
    select 2,1,',-1,1,' union all
    select 3,2,',-1,1,2,' union all
    select 4,3,null union all
    select 5,0,',-1,' union all
    select 6,5,',-1,5,';with maco as
    (
    select * from @T1 where FileID=1
    union all
    select a.* from @T1 a,maco b where a.ParentFileID=b.FileID
    )select * from maco
    /*
    FileID      ParentFileID Path
    ----------- ------------ ----------
    1           0            ,-1,
    2           1            ,-1,1,
    3           2            ,-1,1,2,
    4           3            NULL
    */