When I am trying to use IF Else condition in my stored procedure, I am getting the syntax error
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sortby = 1 THEN value2, value3 ASC;
As per documentation, the syntax is
IF condition THEN
statements;
ELSE
else-statements;
END IF;
My Stored Procedure:
DELIMITER $$
CREATE PROCEDURE test(IN _code INT, IN testformat SMALLINT(5), IN testcurrency CHAR, IN testdate Date, IN tesval CHAR(1), IN sortby INT)
BEGIN
SELECT value1, valu2, value3, value4
FROM shop
WHERE CODE1 = _code
ORDER BY
IF sortby = 1 THEN
value2, value3 ASC;
ELSE
value2, value3 DESC;
END;
END$$
DELIMITER ;
I couldn't find the issue. Thanks for your help.