DELIMITER $$ DROP FUNCTION IF EXISTS `mysql`.`find_value` $$ CREATE FUNCTION `mysql`.`find_value` (formno INT, table_name VARCHAR(50), fieldid INT, field_type VARCHAR(30), scheme_no INT ) RETURNS VARCHAR BEGIN declare findvalue int(10); declare attempts int(1); declare percentage DECIMAL(5,2); IF field_type = 'deg' then select attempts into attempts, (obt_marks*100)/tot_marks into percentage FROM @table_name where form_no = formno and field_id = fieldid; else if field_type = 'sub' then else if field_type = 'fields' then end if END $$ DELIMITER ;