I am trying to write a function that looks for a value assigned to its configuration in a parent-child tree, if the value is null or empty it looks one level up for the value. I am currently getting syntax errors when trying to create the function. This is what i have so far,
DELIMITER //
CREATE FUNCTION `db`.`Configuration`(
`ColumnName` VARCHAR(128),
`CID` INT
)
RETURNS VARCHAR(256)
NOT DETERMINISTIC
BEGIN
DECLARE Config VARCHAR(256) DEFAULT NULL;
DECLARE Parent INT;
WHILE (@Config IS NULL OR @Config = "") DO
SELECT @ColumnName INTO @Config, `ParentID` INTO @Parent FROM `Table` WHERE `ID`=@CID;
END WHILE;
RETURN CONCAT(@Config, '::', @Parent);
END ;
//
DELIMITER ;
I am getting the following error when I try to add the function:
1327 - Undeclared variable: ParentID
Any help would be greatly appreciated!