D = isnull([ParentID],0) from tree where ID = @parentid end set @ReturnValue = '-' + @ReturnValue if @id>0 set @ReturnValue = cast(@id as varchar) + isnull(@ReturnValue,'') if @parentid =0 or @id = @parentid set @ReturnValue = '0-' + isnull(@ReturnValue,'') return(@ReturnValue) --select dbo.GetAllAncestors(10) end go /* 方法一是"高手"的惯性思维把简单的问题搞复杂了,"太累"! 方法二是思路简单清晰,不但是"菜鸟"首选,"高手"也应反思! 若是本题分为两问: 1.求各节点层次信息 2.求属各节点含后代的记录数 可能大家就会受到一些启发! 页码:[1] [2] [3] [4] [5] [6] [7] [8] 第6页、共8页 |