Always returns TRUE
CREATE DEFINER=`root`@`127.0.0.1` PROCEDURE `InsertTransaction`(IN retnum VARCHAR(11), IN amount DECIMAL(19,2), IN dspid INT)
InsertTransaction:BEGIN
DECLARE serialidx INT DEFAULT 0;
DECLARE arcounter INT DEFAULT 0;
DECLARE arnumber VARCHAR(255) DEFAULT NULL;
DECLARE batchidx VARCHAR(255) DEFAULT NULL;
DECLARE retname VARCHAR(255) DEFAULT NULL;
/* Check if there is serial available */
IF NOT EXISTS (SELECT * FROM `nowsms`.`amax_serial` WHERE `InUse` = 1 AND `DSPid` = dspid) THEN
SELECT '-2000' AS Result;
LEAVE InsertTransaction;
END IF;
/* Check for double loading */
IF EXISTS (SELECT * FROM `nowsms`.`amax_transactions` WHERE `Amount` = amount) THEN
SELECT '-2001' AS Result;
LEAVE InsertTransaction;
END IF;
/* Check if retailer has alias and use alias if available */
IF EXISTS (SELECT * FROM `nowsms`.`amax_retailers` WHERE `Number` = retnum) THEN
IF (SELECT `Alias` FROM `nowsms`.`amax_retailers` WHERE `Number` = retnum) IS NOT NULL THEN
SELECT `Alias` INTO retname FROM `nowsms`.`amax_retailers` WHERE `Number` = retnum;
END IF;
END IF;
/* Get info from serial table */
SELECT `ArNum`, `Counter`, `BatchID`, `ID`
INTO arnumber, arcounter, batchidx, serialidx
FROM `nowsms`.`amax_serial`
WHERE `InUse` = 1 AND `DSPid` = dspid;
/* Insert transaction */
INSERT INTO `nowsms`.`amax_transactions` (`ARnum`, `Name`, `Number`, `Amount`, `Type`, `BatchID`, `DSPid`)
VALUES (CONCAT(arnumber, arcounter), retname, retnum, amount, 'DLOAD 1', batchidx, dspid);
/* Update serial counter */
UPDATE `nowsms`.`amax_serial` SET `Counter` = `Counter` + 1 WHERE `ID` = serialidx;
/* OK Result */
SELECT CONCAT(arnumber, arcounter) AS Result;
END
Why this "IF EXISTS (SELECT * FROM `nowsms`.`amax_transactions` WHERE `Amount` = amount)" always returns TRUE even without no existing same amount in the table?
MySQL newbie here...