I know its quite challenging, Is there any sql specialist please kindly help me to solve this.
I Have hierarchyID
like below in NameHID
column. Its representing /NameID/dadID/MomID/
respectively. Which means the students fatherid and the motherID. My Table Name is students.
this is my sample NAMEHID
column
/2/8/5/
/5/11/12/
/8/7/9/
I need a output like
NameID | RecursiveLevel
2 0
5 1
7 2
8 1
9 2
11 2
12 2
From this Pic you can see the what is the RecursiveLevel. This tree representing something like ancestors of a specific node.
I need to show only the NameID and the Recursive level as out put.
if there Any other additional information need to do this?
hierarchyid
is intended to be used. – Metastasishierachyid
with values such as/2/
,/2/8/
,/2/8/7/
,/2/8/9/
, etc. That's how it's intended to be used - each level is represented by adding new values onto the end of the preceding level. If you use that representation, it's trivial to callGetLevel
and obtain the result. Unfortunately, that's not the representation you're using and so all of the features of this data type are now going to work against obtaining sensible results. – Metastasiscreate table(ID int, FatherID int, MotherID int);
populated with sample data will suffice. – Soberminded