select name,value,(select ParentValue from b) as ParentValue from a where OrgID = '001'
declare @lt table(id int,level int)declare @level int
declare @findid int
set @findid = 25/*找nodeId = 25*/
--end of 初始化数据
set @level = 1
insert @lt select @findid,@level
while @@rowcount >0
begin
set @level = @level + 1
insert @lt select a. parentId,@level
from 你的表名 a, @lt b
where a.nodeId = b.nodeId and b.level = @level - 1
end
--连接得到结果
select a.*
from 你的表名 a inner join @lt b
on a.nodeId=b.nodeId
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)