算术溢出错误将数字转换为数据类型数字

时间:2011-05-13 05:26:55

标签: sql

我在2个不同的数据库上执行了此查询:

更新table1集 PresencePayFactor = cast(30为十进制(4,2))/ 30

它正在开发一个但不在另一个上。 这2个数据库是sql server 2008 R2

它出现以下错误 “算术溢出错误将数字转换为数据类型数字。”

可能是什么问题?

1 个答案:

答案 0 :(得分:2)

两者之间的NUMERIC_ROUNDABORT设置不同吗?

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)

相关问题