Get last child from sql hierarchyid
问题 I have hierarchyid in my tables like this. /1/ - This is Category /1/1/ - This is SubCategory /1/1/1/ - This is Item /1/1/2/ - Item /1/1/3/ - Item /1/2/ - SubCategory /1/2/1/ - Item /1/2/2/ - Item /1/2/3 - Item I want to get the last child regardless of Category, Subcategory or Items using SQL Query. For Eg. If its category, It will return /1/ ; If It's Subcategory It should return /1/ or /2/ (second child/last child); If it's Item it should return 3rd child/last child. I tried this query.