谢谢球球版主的耐心回复。
select t3.id, t1.name+'\'+t2.name+'\'+t3.name from tb t1,tb t2, tb t3 where t1.id = t2.rootid and t2.id = t3.rootid
用存储过程也能实现吧?感兴趣的朋友们可以试写一下,当然,不感兴趣的就不用看了。很想看看存储过程是怎么实现的,这几天在学存储过程 ,还望高手指点指点
我这有个,却出错 (显示不全三级):
create procedure GetName(@IDD int,@I int output,@Result varchar(50) output)
/*@IDD叶子节点的ID,@I是返回层级数,@Result是输出字符串*/
as
declare @ID int
declare @TypeName varchar(50)
select @ID=f.id,@TypeName=Z.name from tb f
inner join tb z on z.rootid=f.id
where z.level=@IDD
if @Typename<>''
begin
select @i=@I+1
exec GetName @ID,@I output,@Result output
select @Result=@Result+@Typename+'-'
end
return
/*Run*/
declare @I int
declare @Result varchar(50)
set @Result='类别-'
set @I=1
exec GetName 3,@I output,@Result output