--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

hierarchyid 数据类型的方法 

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
猜你喜欢
  • 2021-07-24
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案