4

I have executed this query on 2 different databases:

Update table1 set PresencePayFactor = cast(30 as decimal (4,2))/ 30

it is working on one but not on the other. the 2 databases are sql server 2008 R2

it is giving the following error "Arithmetic overflow error converting numeric to data type numeric."

What may be the problem?

5
  • have you checked that that column is defined the same way in both databases? Commented May 13, 2011 at 5:36
  • cast(30 as decimal (4,2))/ 30 equals 1.0 Commented May 13, 2011 at 5:36
  • It is the same database restored on 2 different instances. Commented May 13, 2011 at 5:39
  • @Boomer - What is the data type of the column? Commented May 13, 2011 at 5:53
  • but is it a database setting or a query setting, i mean should i set this code before each query executed? Commented May 13, 2011 at 6:56

1 Answer 1

2

Is NUMERIC_ROUNDABORT set differently between the two?

SET NUMERIC_ROUNDABORT OFF
GO
Declare @TestTable Table ( PresencePayFactor decimal(4,2) null )
Insert @TestTable( PresencePayFactor )
Select Cast( 30 As decimal(4,2) ) / 30
GO
-- No error

SET NUMERIC_ROUNDABORT ON
GO
Declare @TestTable Table ( PresencePayFactor decimal(4,2) null )
Insert @TestTable( PresencePayFactor )
Select Cast( 30 As decimal(4,2) ) / 30
-- Arithmetic overflow error converting numeric to data type numeric.

SET NUMERIC_ROUNDABORT (Transact-SQL)

4
  • +1 good call. One of those setting you don't think about usually Commented May 13, 2011 at 6:56
  • but is it a database setting or a query setting, i mean should i set this code before each query executed? Commented May 13, 2011 at 7:05
  • @Boomer - Both. You can override it on a query and you can set a default at the database level. Commented May 13, 2011 at 16:42
  • Hello Thomas. But i executed this script at a database Lvl and executed a CLR script but was still getting this error. It worked only after inserting this script before the execution of my script. anyways it is working now. Thanks again. Commented May 23, 2011 at 8:30

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.