查询无限极分类下的所有子节点

create function   [dbo].[f_getDOWN](@id   int)  
  returns   @re   table(id   int)  
  as  
  begin  
  insert   into   @re   select   id   from   tb_productclass   where   id=@id 
  while   @@rowcount>0  
  insert   into   @re select   a.id    
  from   tb_productclass   a   inner   join   @re   b   on   a.FatherId=b.id  
  where   a.id   not   in(select   id   from   @re)  
  return  
  end  

posted @ 2012-10-18 13:52  放哨De老鼠  阅读(264)  评论(0编辑  收藏  举报