2

I have been using HierarchyID for the last 2 years in some of my tables for obvious purposes

And I have kept a Column (int) for the last node number for example if I have these rows so the int column for number will be

| HierarchyID | Number |
| ----------- | ------ |
| /1/         | 1      |
| /1/5/       | 5      |
| /1/6/       | 6      |
| /2/         | 2      |
| /2/8/       | 8      |
| /2/9/       | 9      |
| /2/1/10/    | 10     |

I have tried to find a way, to extract the last node value without having to convert ToString() and break the string by the "/" char and going to the last item

Is there a better, maybe built-in, way to do it?

I'm using sql2019

thanks

3
  • I'm not sure why you ask that. But I built it within the SQL, again, the column is as HierarchyID
    – Y.G.J
    Commented Sep 27, 2021 at 7:52
  • I mean, are you using hierarchyid methods (GetDescendant(), GetAncestor()) or some external app is generating a hiearchical string and then is parsed and inserted into the database?.
    – McNets
    Commented Sep 27, 2021 at 8:09
  • Yes, I'm using the HierarchyID methods
    – Y.G.J
    Commented Sep 27, 2021 at 8:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.