您的位置:首页 > 数据库

在SqlServer中通过SQL语句实现树状查询

2017-11-01 23:15 429 查看
CREATE PROCEDURE [dbo].[GetTree]
@Id int
AS
BEGIN
with cte as
(
select Id,Pid,Name,0 as lvl from Entity
where Id = @Id
union all
select e.Id,e.Pid,e.Name,lvl+1 from cte c inner join Entity e
on c.Id = e.Pid
)
select * from cte
END
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: