Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    56

    Unanswered: Results for division operation

    Below is a section of a stored procedure that I am currently writing.
    (On db2 7.1 z/os)
    BUDGETEDUNITS_0, BUDGET_MONTHS, and MTHLYUNITS_0 are defined as SMALLINT.


    SELECT INT(ROUND(DEC(BUDGETEDUNITS_0/BUDGET_MONTHS,5,2),0))
    INTO MTHLYUNITS_0
    FROM SYSIBM.SYSDUMMY1;
    ELSE SET MTHLYUNITS_0 = 0;
    END IF;
    ***********************************************
    In testing I have found the following results
    a)
    SELECT INT(ROUND(DEC(707/23,5,2),0))
    AS MTHLYUNITS_0
    FROM SYSIBM.SYSDUMMY1;
    30

    b)
    SELECT INT(ROUND(DEC(707/23.00,5,2),0))
    AS MTHLYUNITS_0
    FROM SYSIBM.SYSDUMMY1;
    31

    c)
    SELECT INT(ROUND(DEC(707/23.0,5,2),0))
    AS MTHLYUNITS_0
    FROM SYSIBM.SYSDUMMY1;
    31

    1) Why am I receivng a difference in responses? Shouldn't I also receive 31 for a?
    2) When dividing does the dividend and divisor have to be defined the same?
    ex: smallint/smallint, int/int, etc

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    1) The first one does an integer division. You did not have a decimal point in any of the operators, so DB2 will not simply switch to another data type. In the other two cases, you have 23.xx, meaning that the division is done with FLOAT or DOUBLE PRECISION.

    2) No, why should it? The system (DB2 or whatever) can just propagate the values to the same type implicitly.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Aug 2007
    Posts
    56
    You're replies are always a big help, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •