I am wacking my head over the problem with this code.
DECLARE @root hierarchyid DECLARE @lastchild hierarchyid SELECT @root = NodeHierarchyID FROM NodeHierar
Use
set @lastchild = dbo.getlastchild(@root)
From CREATE FUNCTION
Scalar-valued functions may be invoked where scalar expressions are used, including computed columns and CHECK constraint definitions. When invoking scalar-valued functions, at minimum use the two-part name of the function.