pvzkch
pvzkch

Reputation: 341

Arithmetic overflow error converting numeric to data type numeric on insert

I am having trouble with this query that shows Arithmetic overflow error.

INSERT INTO seed_health_testing_form (seedlotno, modeoftesting, datetested, 
    datecollected, placecollected, sampleno, germination1, germination2, 
    germination3, germination4, germination5, germination6, germination7, 
    germination8, germination9, germination10, remarks) 
VALUES ( 'A00075', 'GTest', '2/14/2013', 
    '2/19/2013', 'Laguna', 0, 50.00, 50.00, 
    50.00, 50.00, 0.00, 0.00, 0.00, 
    0.00, 0.00, 0.00, '')

Table Design

[id]                [int]       IDENTITY(1,1) PRIMARY KEY NOT NULL
[seedlotno]         [varchar](50)   NULL
[modeoftesting]     [varchar](100)  NULL
[datetested]        [datetime]      NULL
[datecollected]     [datetime]      NULL
[placecollected]    [varchar](100)  NULL
[sampleno]          [int]           NULL
[germination1]      [decimal](3, 2) NULL
[germination2]      [decimal](3, 2) NULL
[germination3]      [decimal](3, 2) NULL
[germination4]      [decimal](3, 2) NULL
[germination5]      [decimal](3, 2) NULL
[germination6]      [decimal](3, 2) NULL
[germination7]      [decimal](3, 2) NULL
[germination8]      [decimal](3, 2) NULL
[germination9]      [decimal](3, 2) NULL
[germination10]     [decimal](3, 2) NULL
[remarks]           [varchar](1000) NULL

I tried breaking the INSERT query line by line to trace where the error was but it always point to Line 1. Still I can't find where my problem is.

Upvotes: 2

Views: 10607

Answers (1)

All of your [decimal](3, 2) data types are the issue.

The (3,2) tells you that the number can have a precision of 3 digits total, with 2 digits being reserved for the decimal portion.

Thus, you only have 1 digit available to store values like 50, which causes the overflow.

See the decmial datatype documentation for more information.

Upvotes: 7

Related Questions