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.
| Author |
Topic |
|
ZarrinPour
Yak Posting Veteran
66 Posts |
Posted - 2008-11-01 : 14:23:01
|
| Hi allCould anyone tell me why the following code causes exception?declare @a decimal(4,4)Set @a=2.95print @aMsg 8115, Level 16, State 8, Line 3Arithmetic overflow error converting numeric to data type numeric.But According to the BOL:decimal[ (p[ , s] )]p (precision) The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal points (scale) The maximum number of decimal digits that can be stored to the right of the decimal point. and 0<=s<=pThanks in advance.Kind Regards.Nothing is quite impossible! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2008-11-01 : 15:30:57
|
| decimal(4, 4) indicates that you want 4 digits total and that you want 4 of those digits to the right of the decimal place, hence 0 to the left. 2.95 has 1 digit to the left of the decimal place, therefore it can't fit.The following works fine, as there's no digit left of the decimal place.declare @a decimal(4,4)Set @a=0.295print @a--Gail ShawSQL Server MVP |
 |
|
|
ZarrinPour
Yak Posting Veteran
66 Posts |
Posted - 2008-11-02 : 11:35:32
|
Thank you GilaMonster Nothing is quite impossible! |
 |
|
|
|
|
|
|
|