简体   繁体   中英

Store “9999999.00000000” in SQL Server 2008 R2: Arithmetic overflow error converting numeric to data type numeric

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

Arithmetic overflow error converting numeric to data type numeric.

Database column is of type DECIMAL(15,8)

Please advise me, how to solve it..

C# Code:

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

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

SQL Server stored procedure:

 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

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.

My SQL test code:

    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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM