在SQL Server 2008 R2中存储“9999999.00000000”:将数值转换为数据类型数字的算术溢出错误

时间:2022-05-31 08:10:42

I am trying to store 9999999.00000000 in SQL Server 2008 R2. But, I was repeatedly facing this error

我试图在SQL Server 2008 R2中存储9999999.00000000。但是,我一再面对这个错误

Arithmetic overflow error converting numeric to data type numeric.

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

Database column is of type DECIMAL(15,8)

数据库列的类型为DECIMAL(15,8)

Please advise me, how to solve it..

请告诉我,如何解决..

C# Code:

C#代码:

  loSqlParameters.Add(new SqlParameter("RUN", loOPERATION_TYPE.RUN.handleDBNull()));

  xxxx.Database.ExecuteSqlCommand("SPNAME".getSql(loSqlParameters), loSqlParameters.Cast<object>().ToArray())

SQL Server stored procedure:

SQL Server存储过程:

 CREATE PROCEDURE [dbo].[SPNAME]  
     @RUN AS DECIMAL(15,8)
 AS    
 BEGIN 
    INSERT INTO TABLENAME (RUN) VALUES  (@RUN)
 END    

Table schema:

表模式:

Column Name     Data Type       Allow Nulls
RUN             decimal(15,8)    yes

1 个解决方案

#1


1  

This works correctly in SQL2008R2 when executed in SSMS. If you run SQL Profiler and capture the SQL text being submitted by your application, you can check the stored procedure call including the parameter(s) being passed to the procedure. It is possible that the parameter value being sent is not what you are expecting to be sent.

这在SSMS中执行时在SQL2008R2中正常工作。如果运行SQL事件探查器并捕获应用程序提交的SQL文本,则可以检查存储过程调用,包括传递给过程的参数。发送的参数值可能不是您期望发送的参数值。

My SQL test code:

我的SQL测试代码:

    CREATE TABLE MyTable
    (
      Run decimal(15, 8) NULL
    );
    GO

    CREATE PROCEDURE dbo.spName
        @Run AS DECIMAL(15,8)
    AS    
    BEGIN 
      INSERT INTO MyTable(Run) VALUES(@Run)
    END;
    GO

    EXEC dbo.spName 9999999.00000000;
    GO

    SELECT *
    FROM MyTable;

#1


1  

This works correctly in SQL2008R2 when executed in SSMS. If you run SQL Profiler and capture the SQL text being submitted by your application, you can check the stored procedure call including the parameter(s) being passed to the procedure. It is possible that the parameter value being sent is not what you are expecting to be sent.

这在SSMS中执行时在SQL2008R2中正常工作。如果运行SQL事件探查器并捕获应用程序提交的SQL文本,则可以检查存储过程调用,包括传递给过程的参数。发送的参数值可能不是您期望发送的参数值。

My SQL test code:

我的SQL测试代码:

    CREATE TABLE MyTable
    (
      Run decimal(15, 8) NULL
    );
    GO

    CREATE PROCEDURE dbo.spName
        @Run AS DECIMAL(15,8)
    AS    
    BEGIN 
      INSERT INTO MyTable(Run) VALUES(@Run)
    END;
    GO

    EXEC dbo.spName 9999999.00000000;
    GO

    SELECT *
    FROM MyTable;