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 |
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-10-17 : 07:46:55
|
InputValue - OutputValue 0.49 - 0.00 0.50 - 1.00 1.51 - 2.00 2.31 - 2.00SELECT ROUND(0.49,0) --0.00SELECT ROUND(0.50,0) --An error occurred while executing batch. Error message is: Arithmetic Overflow.SELECT ROUND(1.51,0) --2.00SELECT ROUND(2.31,0) --2.00I try like these , but why it reflects "Arithmetic Overflow". Other three working fine.================================================When you realize you've made a mistake, take immediate steps to correct it. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-17 : 08:22:39
|
Maybe it is a bug.ButSELECT ROUND(convert(decimal(12,2),0.50),0)works.WebfredPlanning replaces chance by mistake |
|
|
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-10-17 : 08:47:19
|
Thanks for your reply...================================================When you realize you've made a mistake, take immediate steps to correct it. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-17 : 08:52:08
|
[code]select round(data ,0) from( select 0.49 as data union all select 0.50 union all select 1.51 union all select 2.31 ) as t[/code]MadhivananFailing to plan is Planning to fail |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-10-17 : 10:34:41
|
as seperate SELECTs sql was implicitly setting the datatypes of your inputs independently as follows:quote: Originally posted by karthickbabu InputValue - OutputValue 0.49 - 0.00 decimal(2,2) output value ok 0.50 - 1.00 decimal(2,2) output value overflow datatype 1.51 - 2.00 decimal(3,2) output value ok 2.31 - 2.00 decimal(3,2) output value ok
Be One with the OptimizerTG |
|
|
|
|
|
|
|