这样的效果谁能做一个
AAAA 
├—AAAA-1 
│ ├—AAAA-1-1 
├—AAAA-2 
BBBB 
├—BBBB-1 
CCCC 
├—CCCC-1 
└—CCCC-2 

解决方案 »

  1.   

    --写个函数,得到指定id下的所有子id的列表
    create function f_cid(
    @id int
    )returns  varchar(1500)
    as
    begin
    declare @re table([id] int,[level] int)
    declare @l int
    set @l=0
    insert @re select id,@l from class where parentid=@id
    while @@rowcount>0
    begin
    set @l=@l+1
    insert @re select a.[id],@l
    from class a,@re b
    where a.parentid=b.[id] and b.[level]=@l-1
    end
    declare @r varchar(1500)
    set @r=''
    select @r=@r+','+rtrim([id]) from @re
    return(stuff(@r,1,1,''))
    end
    go--生成查询条件
    declare @where varchar(1500)
    select @whwere='id in('+dbo.f_cid(1)+')
    exec GetRecordFromPage
      @strwhere=@where,
     .... --其他条件