Try this
CREATE PROCEDURE [dbo].[uspGetParentNodeId]
@Id INT
AS
BEGIN
SET NOCOUNT ON
DECLARE @ParentId INT
SELECT @ParentId = ParentId
FROM tbYourTable
WHERE Id = @Id
IF @Id IS NULL
BEGIN
RETURN @Id
END
ELSE
BEGIN
EXECUTE uspGetParentNodeId @ParentId
END
END
GO