BEGIN
DECLARE var1 INTEGER;
DECLARE var2 INTEGER;
	BEGIN
	IF input IS NULL THEN
	SET var1 = (SELECT `val1` FROM `TEMP_TABLE` WHERE `id` = 1);
	SET var2 = (SELECT `val2` FROM `TEMP_TABLE` WHERE `id` = 1);
	SET output = var1 + var2;
    DROP TABLE IF EXISTS TEMP_PROC_OUTPUT;
	CREATE TEMPORARY TABLE TEMP_PROC_OUTPUT(
	  `output` int(11)
	) Engine = MyISAM DEFAULT CHARSET=utf8 AS 
	SELECT output;
    SELECT output FROM TEMP_PROC_OUTPUT;
	DROP TABLE IF EXISTS TEMP_PROC_OUTPUT;
	ELSE
	SET var1 = (SELECT `val1` FROM `TEMP_TABLE` WHERE `id` = input);
	SET var2 = (SELECT `val2` FROM `TEMP_TABLE` WHERE `id` = input);
	SET output = var1 + var2;
	DROP TABLE IF EXISTS TEMP_PROC_OUTPUT;
	CREATE TEMPORARY TABLE TEMP_PROC_OUTPUT(
	  `output` int(11)
	) Engine = MyISAM DEFAULT CHARSET=utf8 AS 
	SELECT output;
    SELECT output FROM TEMP_PROC_OUTPUT;
	DROP TABLE IF EXISTS TEMP_PROC_OUTPUT;
	END IF;
	END;
END