Stored Procedure
CREATE DEFINER=`root`@`localhost` PROCEDURE `Sample`(IN itemId INT, IN itemQnty
DOUBLE, IN invID INT)
BEGIN
DECLARE crntQnty DOUBLE;
DECLARE nwQnty DOUBLE;
SET crntQnty=(SELECT `QuantityOnHand` FROM `item` WHERE id=itemId);
SET nwQnty=itemQnty+crntQnty;
UPDATE `item` SET `QuantityOnHand`=nwQnty WHERE `Id`=itemId;
UPDATE `inventoryentry` SET `Status` = 1 WHERE `InventoryID`=invID AND
`ItemID`=itemId;
END$$
In this stored procedure I have two update statements. IF first update execute successfully then second execute. what changes required to be made?
After the first
UPDATEyou can check the number of rows that were affected byROW_COUNT().If the
ROW_COUNT()returns the desired number of updates you want (maybe > 0) then only fire secondUPDATE.Yo can surround the second
UPDATEby anIF - END IFchecking for the number of rows that were affected.