日期:2014-05-18 浏览次数:20557 次
create function f_getChild(@ID VARCHAR(10)) returns @t table(ID VARCHAR(10),PID VARCHAR(10),Level INT) as begin declare @i int set @i = 1 insert into @t select ID,PID,@i from BOM where PID = @ID while @@rowcount<>0 begin set @i = @i + 1 insert into @t select a.ID,a.PID,@i from BOM a,@t b where a.PID=b.ID and b.Level = @i-1 end return end
create function f_getChild(@ID VARCHAR(10)) returns varchar(500) as begin declare @i int,@s varchar(500) declare @t table(ID VARCHAR(10),PID VARCHAR(10),Level INT) set @i = 1 insert into @t select ID,PID,@i from BOM where PID = @ID while @@rowcount<>0 begin set @i = @i + 1 insert into @t select a.ID,a.PID,@i from BOM a,@t b where a.PID=b.ID and b.Level = @i-1 end select @s=isnull(@s+',','')+ltrim(ID) from @t return @s end
------解决方案--------------------