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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ROUND Function Issue

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.00

SELECT ROUND(0.49,0) --0.00
SELECT ROUND(0.50,0) --An error occurred while executing batch. Error message is: Arithmetic Overflow.
SELECT ROUND(1.51,0) --2.00
SELECT ROUND(2.31,0) --2.00

I 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.
But
SELECT ROUND(convert(decimal(12,2),0.50),0)
works.

Webfred

Planning replaces chance by mistake
Go to Top of Page

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.
Go to Top of Page

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]


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 Optimizer
TG
Go to Top of Page
   

- Advertisement -