I am wacking my head over the problem with this code.
DECLARE @root hierarchyid DECLARE @lastchild hierarchyid SELECT @root = NodeHierarchyID FROM NodeHierar
Try
set @lastchild = dbo.getlastchild(@root)