HierarchyId通过父节点创建一个新的子节点

--HierarchyId通过父节点创建一个新的子节点
CREATE TABLE #temp(
node HierarchyID
);

insert into #temp
select '/' union all
select '/1/' union all
select '/2/' union all
select '/1/1/' union all
select '/1/2/' union all
select '/1/1/1/' union all
select '/1/1/1/1/'

declare @HyId hierarchyid=HierarchyID::Parse('/1/2/');--父级节点
declare @NewHyId hierarchyid;

select @NewHyId=@HyId.GetDescendant(MAX(node),null) from #temp Where node.GetAncestor(1)=@HyId--创建一个新的节点

insert into #temp(node) values(@NewHyId)
select *,node.ToString() from #temp

猜你喜欢

转载自www.cnblogs.com/hllive/p/10006803.html