Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Trova tutti i record dei nodi foglia usando gerarchiid

SELECT A.HieracrchyId, A.HierarchyId.ToString()
  FROM dbo.TableA AS A 
  LEFT OUTER JOIN dbo.TableA AS B
  ON A.HierarchyId = B.HierarchyId.GetAncestor(1)
  WHERE B.HierarchyId IS NULL;