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
转载于:https://www.cnblogs.com/zhang9418hn/archive/2012/10/18/2729382.html