mercredi 23 octobre 2019

MySQL IF() Function does not work anymore

I have a database running for over two years now. Recently, I decided that it would be a good idea to change the collation of the whole schema and all the tables to one other than utf8_general_ci. Shortly after that, I received complaints from the user, upon which I reverted all the changes I had made to the schema and I thought I could sleep easy. But after a while, I received yet other complaints and got to work to pinpoint the issue, and so did I.

It turned out that one statement in one of the stored procedures did not return the desired result. It is something like this:

    SELECT
        A, -- BIGINT(24)
        B, -- BIGINT(24)
        C, -- BIGINT(24)
        D, -- ENUM('VALUE_A', 'VALUE_B', 'VALUE_C')
    INTO
        @W, @X, @Y, @Z
    FROM
        `my_table`
    WHERE
        some_field = in_sproc_param; -- in_sproc_param (IN VARCHAR(64)) -> parameter to the stored procedure

    SET @T = @W + @X;

    SET @Q = IF(@Z <> 'VALUE_C' AND @T >= @Y, 'TRUE', 'FALSE');
    -- '

The IF() function always returns FALSE, regardless of what values you pass to it. Does anyone have any idea why?

Aucun commentaire:

Enregistrer un commentaire