zoukankan      html  css  js  c++  java
  • 123123

    if exists (select * from sysobjects where name='proc_menu_select')
    drop procedure proc_menu_select
    go
    create proc proc_menu_select(@id int,@t int)
    as
        declare @i int 
        declare @count int, @tmpid int
        create table #tb(id int,name varchar(50),pId int,level int,sort int)
        select @count=COUNT(1) from tb_Menu where pId=@id
        insert #tb select m.id,m.name,m.pId,m.level,m.sort from tb_Menu m  where pId=@id
        select * from #tb
        select @i=level-1 from tb_Menu where pId=@id
                while(@count<>0)
                    begin
                    set @i=@i+1
                    print @i
                      select @count=COUNT(1) from tb_Menu m left join #tb on #tb.id=m.pId where #tb.level=@i-1
                      insert #tb select m.id,m.name,m.pId,m.level,m.sort from tb_Menu m left join #tb on #tb.id=m.pId where #tb.level=@i-1
                    end    
                select id,name,pId,level,sort from #tb
        
    go
    exec proc_menu_select 4,1
    select * from tb_Menu;
    select * from tb1
  • 相关阅读:
    test20180922 倾斜的线
    test20180921 量子纠缠
    test20180921 手机信号
    test20180919 选择客栈
    BZOJ3083 遥远的国度
    test20180907 day1
    [ZJOI2010]基站选址
    HDU3584 Cube
    POJ2155 Matrix
    test20180902 day1
  • 原文地址:https://www.cnblogs.com/wzq806341010/p/3450120.html
Copyright © 2011-2022 走看看