查找父类下的所有子类 create   function   f_child(@pid   int)   
查找父类下的所有子类  
returns   @re   table(id   int,l int)   
查找父类下的所有子类  
as   
查找父类下的所有子类  
begin   
查找父类下的所有子类  
declare   @l   int   
查找父类下的所有子类  
set   @l=0   
查找父类下的所有子类  
insert   @re   select   id,@l   from   category   where  parentid=@pid   
查找父类下的所有子类  
while   @@rowcount>0   
查找父类下的所有子类  
begin   
查找父类下的所有子类  
set   @l=@l+1   
查找父类下的所有子类  
insert   @re   select   a.id,@l   
查找父类下的所有子类  
from   category   a   join   @re   b   on   a.parentid=b.id   
查找父类下的所有子类  
where   b.l=@l-1   
查找父类下的所有子类  
end   
查找父类下的所有子类  
return   
查找父类下的所有子类  
end
查找父类下的所有子类


相关文章: