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
本文介绍了一种使用SQL递归查询的方法,通过创建一个存储过程来获取产品分类及其子分类的所有ID。该方法利用了自连接和while循环,确保了查询结果的完整性。
1370

被折叠的 条评论
为什么被折叠?



