This is my query that basically takes two numbers that adds them and multiplies the sum by 10
DELIMITER $$
CREATE FUNCTION tot(a int(4),b INT(4)) RETURNS INT(4)
BEGIN
RETURN ROUND((a+b)*10/9);
END $$
DELIMITER ;
everything is working fine , but I was wondering if there was a way I could add an IF ELSE that checks if any of of the values entered is null and if so the null value is assigned a value of zero
I've tried this but I'm getting an error
DELIMITER $$
CREATE FUNCTION tot(a int(4),b INT(4)) RETURNS INT(4)
BEGIN
IF (a = "") then
a=0;
ELSE IF (b = "")
b=0;
ELSE
END IF;
RETURN ROUND((a+b)*10/9);
END $$
DELIMITER ;
NULLis not the same thing as an empty string.ELSE IFshould only be used when the conditions are mutually exclusive. What if bothaandbare null?ELSE a=a;is necessary? Why would you need to assign a variable to itself.