首页 > 其他 > 详细

控制树的查询深度

时间:2019-09-16 13:10:34      阅读:92      评论:0      收藏:0      [点我收藏+]

-- 控制树的查询深度
ALTER VIEW [dbo].[V_GoodsCategoryTree]
AS
WITH GoodsCategoryTree
AS
(
select GCId, GCCode, GCParentCode, GCParentCode AS TopParentCode,
(select gc.GCName from GoodsCategory as gc where gc.GCCode = GoodsCategory.GCParentCode) AS TopParentName,
GCCode AS SubClassCode, 1 AS depth from GoodsCategory
where GCParentCode IN(select GCCode from GoodsCategory where GCParentCode = ‘‘ )
union all
select r.GCId,r.GCCode,r.GCParentCode,TopParentCode,TopParentName,SubClassCode, depth + 1 as depth from GoodsCategory as r
join GoodsCategoryTree as rp on r.GCParentCode = rp.GCCode
)
select * from GoodsCategoryTree


GO

控制树的查询深度

原文:https://www.cnblogs.com/morpheusliu/p/11526506.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!