lundi 29 octobre 2018

SQL Stored Process: If statement not behaving as expected

Attempting to create a stored process for MySQL. It contains a basic if-statement. The current script is below:

DROP PROCEDURE IF EXISTS sp_pay_raise;

DELIMITER @@
CREATE PROCEDURE sp_pay_raise
     (IN inEmpId INT,
      IN inPercentageRaise DOUBLE(4,2),
      OUT outErrorCode INT)
BEGIN
    IF (@inPercentageRaise <= 0.0) THEN
        SELECT -3 INTO errorCode
    ELSE
        SELECT -2 INTO errorCode
    END IF;
END @@
DELIMITER ;

The above doesn't work as expected. If I provide a inPercentageRaise which is less than zero, for ex.

CALL sp_pay_raise(0,-1.0, @out)
SELECT @out;

The database shows @out = -2. Is the if-statement which is written incorrectly?

Aucun commentaire:

Enregistrer un commentaire