T-Sql 递归查询(给定节点查所有父节点.所有子节点的方法) -- 查找所有父节点with tab as( select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=316--子节点 union all select b.Type_Id,b.ParentId,b.Type_Name from tab a,--子节点数据集 Sys_ParamType_V2_0 b --父节点数据集 where a.
原文:在论坛中出现的比较难的sql问题:21(递归问题 检索某个节点下所有叶子节点) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路. 问题:求SQL:检索某个节点下所有叶子节点 部门表名:tb_department id int --节点id pid int --父节点id caption varchar
-- 查找所有父节点with tab as( select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=316--子节点 union all select b.Type_Id,b.ParentId,b.Type_Name from tab a,--子节点数据集 Sys_ParamType_V2_0 b --父节点数据集 where a.ParentId=b.Type_Id --子节点数据集.paren
-->Title:Generating test data -->Author:wufeng4552 -->Date :2009-09-30 08:52:38 set nocount on if object_id('tb','U')is not null drop table tb go create table tb(ID int, ParentID int) , , , , , , , -->Title:查找指定節點下的子結點 if object_id('Uf_GetChil
;with cte as( select id,ParentCategoryId from Category where id = 17 union all select a.id,a.ParentCategoryId from Category a join cte b on a.ParentCategoryId = b.id where a.id is not null) select * from cte
;with cte as ( select * from Associator where No = 'mc1007' union all select air.* from Associator as air inner join cte on air.ParentNo = cte.No ) select * from cte;