If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Results for division operation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-07-08, 09:56
citi citi is offline
Registered User
 
Join Date: Aug 2007
Posts: 45
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
Reply With Quote
  #2 (permalink)  
Old 03-07-08, 12:24
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #3 (permalink)  
Old 03-07-08, 13:27
citi citi is offline
Registered User
 
Join Date: Aug 2007
Posts: 45
You're replies are always a big help, thank you!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On