Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Cast formula

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-04-10 : 09:06:48
I have a quick question. created a report with this formula below. It works when I put a date range from 1-1-2007 to 2-1-2007, but when I put in a date range of 03-01-2008 through 03-31-2008. i get an error message of arithmetic overflow error converting numeric to data type numberic.

So instead of haveing the formula below be (4,2) I put it as (5,2) and now it work. Why is that?

CAST(clm_sppo / clm_tchg * 100 AS decimal(4, 2)) AS PercentSavings

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-10 : 09:07:53
CAST(clm_sppo / clm_tchg * 100.0 AS decimal(4, 2)) AS PercentSavings

to avoid integer math


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-10 : 09:08:28
100,00 is five "digits". So you have to use DECIMAL(5, 2).



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-04-10 : 09:20:03
Thanks for all of your help.
Go to Top of Page
   

- Advertisement -