Whenever I try to create the below stored procedure.
CREATE PROCEDURE purchaseItem (IN productID INT, IN quantity INT, IN price DECIMAL(10,2) , IN memID INT)
BEGIN
DECLARE qnty INT DEFAULT 0;
SELECT p_Unit INTO qnty FROM product WHERE p_ID = productID;
IF qnty >= quantity && qnty != 0 THEN
INSERT INTO purchase VALUES (NULL, productID, quantity, price, memID, 0, NULL);
UPDATE product SET p_Unit = (qnty - quantity) WHERE p_ID = productID;
END IF;
END;
I get the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
Can someone please point out me where I’m doing wrong.
Thanks!
Don’t forget to change the
DELIMITER, try the following query without usingSELECT..INTO