存储过程递归查询
用户表结构中包含用户及其子用户,使用以下方法递归查询当前用户及其子用户信息
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