1

I am receiving the error

Arithmetic overflow error converting expression to data type float

on the following code:

SELECT b.[CUSIP NUMBER],
   b.[PASS THRU RATE],
   a.[CURRENT BALANCE],
   b.[ORIGINAL WA MATURITY],
   b.[CURRENT WA MATURITY],
   (b.[ORIGINAL BALANCE] * ((b.[PASS THRU RATE]*.01)/12))/ (1-((1 + power (( (b.[PASS THRU RATE]*.01 )/ 12), -b.[ORIGINAL WA MATURITY] ) )))

   FROM DBO.mbs012013 a, DBO.mbs022013 b
   WHERE a.[CUSIP NUMBER] = b.[CUSIP NUMBER]

I have not designated the numbers to be any specific type so I am not sure why I am receiving this error. If any one can tell me how to fix this it would greatly appreciated.

For reference: cusip number is a serial number, the rest are inputs (interest rate, bank balance, maturity in months, etc.)

11
  • 2
    And what database system is this for? SQL is just the query language - used by many databases. We need to know if this is for Oracle, Postgres, MySQL, SQL Server, IBM DB2 or something else. Please add the relevant and meaningful tags - thanks! Commented Jun 20, 2013 at 18:26
  • Sorry about that, its SQL Server Commented Jun 20, 2013 at 18:28
  • possible duplicate of Arithmetic overflow error converting numeric to data type numeric and Arithmetic overflow error in SQL Commented Jun 20, 2013 at 18:29
  • 2
    You probably divide by zero or something like this Commented Jun 20, 2013 at 18:30
  • 2
    There is no datatype in SQL Server that can cope with 10^360 Commented Jun 20, 2013 at 18:51

2 Answers 2

2

You say PASS THRU RATE can be 1-10 and ORIGINAL WA MATURITY between 0 - 360.

The worst possible case for you then would be PASS THRU RATE = 1 and ORIGINAL WA MATURITY = 360

In that case you would be doing

SELECT POWER(0.0008333333333, -360)

Which has a result of 3.2E+1108. No Datatype in SQL Server has a greater range than float and that "only" allows a range of ± 1.79E+308.

If you need to do these calculations then they will need to be done outside of TSQL. But are you sure that your formula is actually correct?

It shouldn't be one of these?

SELECT POWER(1 + 0.0008333333333, -360)

SELECT POWER(1 - 0.0008333333333, -360)
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is probably here:

power (( (b.[PASS THRU RATE]*.01 )/ 12), -b.[ORIGINAL WA MATURITY] )

If b.[PASS THRU RATE] is small and -b.[ORIGINAL WA MATURITY] is large you can end up with a result that is larger than the NUMERIC type can hold. Try casting them to floats:

power (( CAST(b.[PASS THRU RATE]*.01 / 12) AS FLOAT), -b.[ORIGINAL WA MATURITY] ) )))

3 Comments

The error message is complaining about overflow converting to float though.
@MartinSmith - Curiously, select Power( .01, -350 ) results in Arithmetic overflow error converting expression to data type float..
@HABO - Well that is 1E+700. Float goes up to 1.79E+308

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.