日期:2014-05-18 浏览次数:20504 次
--这个是函数法,正好开着,就贴给你,栏位名自己改改 ALTER function [dbo].[fn_bom]( @parent_part varchar(30)) returns @t_level table(part varchar(30),level int) AS begin declare @level int set @level=0 insert into @t_level select @parent_part,@level while @@rowcount>0 begin set @level=@level+1 insert into @t_level select a.child_part,@level from T_bom a,@t_level b where a.parent_part=b.part and b.level=@level-1 end return end