473,883 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overflow error????

Hi I am writing a select statement that has an arithmetic function
inside a case statement that uses logic to decide whether to divide or
multiply and when I run the arithmetic statements outside the case
statement they work fine, but blow up with an overflow error in the
case statement. The select looks like:

SELECT a.acct_cd,
a.crrncy_cd,
a.mkt_val,
c.rate,
a.mkt_val / c.mrrate,
a.mkt_val * c.mrrate,
CASE
WHEN b.mcopr = 'M' THEN a.mkt_val / c.mrrate
WHEN b.mcopr = 'D' THEN a.mkt_val * c.mrrate
END
FROM account a,
exchange_calcs b,
exchange_rates c
WHERE b.currency = a.crrncy_cd
AND c.currency = b.currency
AND c.datetime = 1070531;

If I comment out the case statement above it works perfectly, with the
case statement active it gives the following error:

[SQL0802] Data conversion or data mapping error. Cause . . . . . :
Error type 1 has occurred. Error types and their meanings are: 1 --
Arithmetic overflow. 2 -- Floating point overflow. 3 -- Floating point
underflow. 4 -- Floating point conversion error. 5 -- Not an exact
result. 6 -- Numeric data that is not valid. 7 -- Double-byte
character set (DBCS) or UTF-8 data that is not valid. 8 -- Division by
zero. 9 -- Hash value cannot be computed for the requested query. 10
-- User-defined function returned a mapping error. 11 -- Not valid
length found in a varying-length column returned from an array result
set. 12 -- Result of a concatenation operation on a varying-length
field exceeded the maximum allowed length of the result type. If the
error occurred when assigning a value to a host variable of a FETCH,
embedded SELECT, SET, or VALUES INTO statement, the host variable name
is *N and the relative position of the host variable in the INTO
clause is 0. If the host variable name is *N, the error occurred when
attempting to resolve a search condition. If more than one data
mapping error occurred, this is a description of the first error that
occurred. For a description of any other data mapping errors, see the
previously listed messages in the job log. Recovery . . . : The
error was caused by data that was not valid or that was too large.
Look at the previously listed messages in the job log (DSPJOBLOG
command) or press F10 (Display messages in job log) on this display to
determine what row and columns were involved in the error. Correct
the data and then try the request again.

Jun 1 '07 #1
3 10753
je****@gmail.co m wrote:
Hi I am writing a select statement that has an arithmetic function
inside a case statement that uses logic to decide whether to divide or
multiply and when I run the arithmetic statements outside the case
statement they work fine, but blow up with an overflow error in the
case statement. The select looks like:

SELECT a.acct_cd,
a.crrncy_cd,
a.mkt_val,
c.rate,
a.mkt_val / c.mrrate,
a.mkt_val * c.mrrate,
CASE
WHEN b.mcopr = 'M' THEN a.mkt_val / c.mrrate
WHEN b.mcopr = 'D' THEN a.mkt_val * c.mrrate
END
What are the datatypes of mkt_val and mrrate?
Note that the case-EXPRESSION (:-)) has to derive a final result type
for both expressions. Maybe the overflow occurs in that assignment.
Describe the columns for the /, * and CASE entries.

What version of DB2 for zOS is this btw?
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 1 '07 #2
What are the datatypes of mkt_val and mrrate?
Note that the case-EXPRESSION (:-)) has to derive a final result type
for both expressions. Maybe the overflow occurs in that assignment.
Describe the columns for the /, * and CASE entries.
mkt_val is a DECIMAL(17,2) and mrrate is a DECIMAL(15, 9).
What version of DB2 for zOS is this btw?
I am not sure what version of DB2 this is but it is running on an
AS400.
Jeremy.

Jun 4 '07 #3
According to the manual "DB2 UDB for iSeries SQL Reference Version 5
Release 4".
(Note 1)
The symbol mp denotes the maximum precision.
The value of mp is 63 if:
- either w or y is greater than 31, or
- a value of 63 was explicitly specified for the maximum precision.
Otherwise, the value of mp is 31.

The symbol ms denotes the maximum scale.
The default value of ms is 31. ms can be explicitly set to any number
from 0 to the maximum precision.

The symbol mds denotes the minimum divide scale.
The default value of mds is 0. mds can be explicitly set to any number
from 0 to the maximum scale.

(Following calculations, I assumed mp, ms and mds are default(i.e. 31,
31, 0).)

DECIMAL(p,s) / DECIMAL(p',s')
=: ( (p-s+s') + max(mds, min(ms, mp - (p-s+s') ) ), max(mds, min(ms,
mp - (p-s+s') ) ) )

Apply the rule for this case.
a.mkt_val / c.mrrate
=: DECIMAL(17,2) / DECIMAL(15, 9)
=: ( (17-2+9) + MAX(0, MIN(31, 31-(17-2+9))), MAX(0, MIN(31,31-
(17-2+9))) )
=: ( (24 + MAX(0, MIN(31, 7)), MAX(0, MIN(31, 7)) )
=: DECIMAL( 31, 7 )
(Integer part is 24 digits, fractional part is 7 digits)

DECIMAL(p,s) * DECIMAL(p',s')
=: ( min (mp,p+p), min(ms,s+s) )

Apply the rule for this case.
a.mkt_val * c.mrrate
=: DECIMAL(17,2) / DECIMAL(15, 9)
=: DECIMAL( MIN(31,17+15), MIN(31,2+9) )
=: DECIMAL( 31, 11 )
(Integer part is 20 digits, fractional part is 11 digits)

CASE expression
One operand column is ...
DECIMAL(w,x)
Another operand column is ...
DECIMAL(y,z) or NUMERIC(y,z,)
The data type of the result column is...
DECIMAL(p,s) where p = min(mp, max(x,z)+max(w-x,y-z)) s = max(x,z)
mp = 31 or 63 (See Note 1)

Apply the rule for this case.
a.mkt_val / c.mrrate
=: DECIMAL(w,x) =: DECIMAL(31,7)
a.mkt_val * c.mrrate
=: DECIMAL(y,z) =: DECIMAL(31,11)
Result is
DECIMAL( min(mp, max(x,z)+max(w-x,y-z)), max(x,z) )
=: DECIMAL( MIN(31, MAX(7,11)+MAX(3 1-7,31-11)), MAX(7,11) )
=: DECIMAL( MIN(31, 11+24), 11 )
=: DECIMAL( 31, 11 )
(Integer part is 20 digits, fractional part is 11 digits)

(I might made some mistake. Because, calculations are complex.)

Anyway, my guess is that "a.mkt_val / c.mrrate" made overflow at the
time used in CASE expression.
Because, if "a.mkt_val / c.mrrate" is used in a column, result is
DECIMAL( 31, 7 ) (Integer part is 24 digits, fractional part is 7
digits)
While, if it is used in CASE expression with "a.mkt_val * c.mrrate",
result is
DECIMAL( 31, 11 ) (Integer part is 20 digits, fractional part is 11
digits)
Jun 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3291
by: Mike | last post by:
I am trying to use the bulk insert command but I am getting the following error: ---Begin Error Msg--- Server: Msg 4867, Level 16, State 1, Line 1 Bulk insert data conversion error (overflow) for row 1, column 3 (PRICE). ---End Error Msg--- The data is formatted as a number, single with 14 decimal. I am exporting to csv txt file from MS-Access.
2
8687
by: Robert McEuen | last post by:
Using Access 97, Windows XP I'm receiving a Numeric Field Overflow error during text import that I did not receive before I split my database. Another thread I found suggested that the cause of this error might be due to columns on the text file being in a different order than fields in the destination table, but they're the same in my case. I'm thinking a workaround might be to import to a temp table in the front-end, run an append...
7
2157
by: MLH | last post by:
?2944*24 gives me an overflow error, entered in the immediate window. Anybody else?
4
12900
by: Chua Wen Ching | last post by:
Thanks Derek... Okay i had another question.. my program runs smoothly for the first minute, after 1 minute... suddenly it breaks and display this error: do you know what is the cause of this problem...
4
548
by: vir | last post by:
we use an E-office application where server is SQL server 7.0 and client side its MS access In our VB program we use ASP to synchronization and update client database from server and each table is updated afresh . This program was running fine and all tables were being Updated until number of records in 1 table went above 3000 . Now this table gives overflow error while others are being updated correctly . the error is 'Error in...
3
6584
by: capes | last post by:
Hi, I have a structure called Tissue and I use it in a matrix like this: vector < vector < Tissue* tissueArray(cRows); This whole function works great for a matrix size of 2X2 to 15X15. Beyond that it crashed with a STATUS_STACK_OVERFLOW exception!!! 1. Why does his happen? 2. How do I fix it? 3. At some point I may go to a 300X300 array. What happens then?
1
3321
by: zaneh | last post by:
I have found TheScripts a very useful site, but however I cannot find an answer to a problem I am having, so I finally have to ask the question! I am getting an Overflow error in a Function I have written. BUT... It does not occur all the time. If I call the Function from the "After Update" event for a checkbox, it works as intended, how ever if I call the Function from the "On Load" event of the Form, testing to see whether the...
3
2166
by: MLH | last post by:
A wide comma delimited text file import into A97 failed with an overflow error. I'm estimating it to have been no more than 1000 records. 100% of all the fields were quoted strings or ZLS's. What most likely caused the overflow? Might it be upper limit on number of fields in table?
3
2263
by: Tophurious | last post by:
Ok, I've been working on this for two days and have finally resulted to asking for help. I am designing a program for my work that will emulate the thermodynamic systems of a power plant. however, I have a very simple issue that I cannot seem to fix... here is the code snippet: Property Get Eff() As Double 'Efficiency of the Turbine If pType = HP Then Dim I As Integer Dim OutEnth As Double 'Enthalpy Dim...
0
9932
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11109
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5979
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4602
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.