简体   繁体   English

在SQL Server 2008中将varchar转换为数值数据类型时发生算术溢出错误

[英]An arithmetic overflow error occurred while converting varchar to numeric data type in SQL Server 2008

I have a table in SQL Server 2008: 我在SQL Server 2008中有一张表:

Create table ExTable1 
(
     Fcur varchar(50),
     Tcur varchar(50),
     Rt numeric(10,10)
)

I am trying to insert the data 我正在尝试插入数据

Insert into [DB].[dbo].[ExTable1 ](Fcur, Tcur, Rt) 
values ('INR', 'EUR', 1) 

Error I am getting is 我得到的错误是

An arithmetic overflow error occurred while converting varchar to numeric data type. 将varchar转换为数值数据类型时发生算术溢出错误。

When I change datatype of column Rt to numeric(10,2) , above mention query mentioned perfectly fine. 当我将列Rt数据类型更改为numeric(10,2) ,上面提到的查询提到的效果很好。

Data which I am going to insert in Rt column may have 10 digits after decimal. 我要在Rt列中插入的数据可能在十进制后有10位数字。

How to fix this? 如何解决这个问题?

Basically I got this exception in C# code. 基本上,我在C#代码中遇到了此异常。 So I tried executing the QueryString which was create in C# , directly in SQL server. 因此,我尝试直接在SQL Server中执行在C#中创建的QueryString。 I faced the same error. 我遇到了同样的错误。

Thanks 谢谢

Numeric(10,10) will define a number consisting of decimals only... Numeric(10,10)将定义仅由小数组成的数字...

Try it with Numeric(11,10) (one place before and 10 after the comma). 尝试使用Numeric(11,10) (逗号前一个位置,逗号后十个位置)。

The first parameter defines the full width, the second the number of places behind the comma within the full width, read here . 第一个参数定义完整宽度,第二个参数定义完整宽度逗号后面的位数, 请参见此处

decimal[ (p[ , s] )] and numeric[ (p[ , s] )] Fixed precision and scale numbers. 十进制[(p [,s])]和数值[(p [,s])]固定的精度和小数位数。 When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). 使用最大精度时,有效值为-10 ^ 38 +1到10 ^ 38-1。十进制的ISO同义词是dec和dec(p,s)。 numeric is functionally equivalent to decimal. 数字在功能上等同于十进制。

p (precision) The maximum total number of decimal digits that will be stored, both to the left and to the right of the decimal point. p(精度)在小数点左边和右边都将存储的最大十进制数字总数。 The precision must be a value from 1 through the maximum precision of 38. The default precision is 18. 精度必须是1到最大精度38之间的值。默认精度是18。

s (scale) The number of decimal digits that will be stored to the right of the decimal point. s(刻度)将存储在小数点右边的小数位数。 This number is substracted from p to determine the maximum number of digits to the left of the decimal point. 从p中减去此数字可确定小数点左边的最大位数。 The maximum number of decimal digits that can be stored to the right of the decimal point. 可以存储在小数点右边的最大小数位数。 Scale must be a value from 0 through p. 小数位数必须是0到p之间的值。 Scale can be specified only if precision is specified. 仅当指定精度时才能指定比例。 The default scale is 0; 默认比例为0; therefore, 0 <= s <= p. 因此,0 <= s <= p。 Maximum storage sizes vary, based on the precision. 最大存储大小取决于精度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#和SQL Server将int转换为数据类型数值的算术溢出错误 - Arithmetic overflow error converting int to data type numeric using C# and SQL Server 将varchar转换为数值数据类型的算术溢出错误。 asp.net中的错误 - Arithmetic overflow error converting varchar to data type numeric. Error in asp.net 在var.net中将varchar转换为数值类型的算术溢出错误 - Arithmetic overflow error converting varchar to data type numeric in asp.net 将varchar转换为数值数据类型的算术溢出错误。 尝试从数据库读取时并非每次都会发生 - Arithmetic overflow error converting varchar to data type numeric. when trying to read from a database DOES NOT happen every time 流利的NHibernate在插入/保存时导致“将数字转换为数据类型数字的算术溢出错误” - Fluent NHibernate cause an “Arithmetic overflow error converting numeric to data type numeric” on insert/save c# 中的 ExecuteNonQuery() 抛出异常 - 将数字转换为数据类型数字的算术溢出错误 - ExecuteNonQuery() from c# throwing exception - arithmetic overflow error converting numeric to data type numeric SQLException:将数据类型varchar转换为数值时出错 - SQLException: Error converting data type varchar to numeric 将表达式转换为数据类型 int 的算术溢出错误 - Arithmetic overflow error converting expression to data type int WINFORM算术溢出错误将表达式转换为数据类型int - WINFORM arithmetic overflow error converting expression to data type int 将表达式转换为数据类型nvarchar的算术溢出错误 - Arithmetic overflow error converting expression to data type nvarchar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM