存储过程递归查询

Posted ypyp123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了存储过程递归查询相关的知识,希望对你有一定的参考价值。

用户表结构中包含用户及其子用户,使用以下方法递归查询当前用户及其子用户信息

with Tusers as(
select UserID,PUserID from [Base].[WGUser] where UserID=1
union all
select B.UserID,B.PUserID from [Base].[WGUser] as B
inner join Tusers as A on A.UserID=B.PUserID
and B.IsValid=1
)
select * from Tusers

以上是关于存储过程递归查询的主要内容,如果未能解决你的问题,请参考以下文章