[英]Arithmatic overflow error converting varchar to data type numeric in sql server
I am trying to insert data from one table to another table, but we are facing issue it gives us error of 我正在尝试将数据从一个表插入到另一个表,但是我们面临的问题是它给我们带来了错误
Numeric value out of range: 8115 [Microsoft][ODBC Driver 11 for SQL Server][SQL Server ]Arithmetic overflow error converting varchar to data type numeric. (SQLExecDirect[8115] at /builddir /build/BUILD/php-5.6.30/ext/pdo_odbc/odbc_driver.c:247)
We are using below query to insert data 我们正在使用下面的查询来插入数据
`INSERT INTO template_150 ([ClientName],[LOB],[PharmacyTotalClaimAmt])
SELECT PharmacyID,ProductIDNDC
, REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(decimal(10,2),CONVERT(varchar(10),CONVERT(varchar(10),LEFT
(SUBSTRING(REPLACE(TRIM(IngredCost),'\',''), PATINDEX('%[0-9.-]%',REPLACE(TRIM(IngredCost),'\','')),
8000),PATINDEX('%[^0-9.-]%', SUBSTRING(REPLACE(TRIM(IngredCost),'\',''), PATINDEX('%[0-9.-]%',REPLACE
(TRIM(IngredCost),'\','')), 8000) + 'X') -1)) )
),'"',''),'$',''),',',''),'-','') AS [TRIM(IngredCost)]
FROM file_5979bd211a3a9`
I found some solution to use lenth WHERE LEN(IngredCost )<=13
function in where condition, but if we will use this function then we will not able to insert all the records for the table file_5979bd211a3a9
, we want to save all the records of table file_5979bd211a3a9
, can anyone please give us solutio, how can we resolve this error ? 我找到了一些解决方案,可以在where条件下使用WHERE LEN(IngredCost )<=13
函数,但是如果我们将使用此函数,那么我们将无法插入表file_5979bd211a3a9
所有记录,我们想保存的所有记录表file_5979bd211a3a9
,任何人都可以给我们解决方案,我们如何解决此错误?
You're converting a 10 character number to a DECIMAL(10,2)
. 您正在将10个字符的数字转换为DECIMAL(10,2)
。 That means up to 8 digits in the whole portion and 2 in the fractional. 这意味着整个部分最多8位数字,小数部分最多2位数字。 If there are more than 8 numbers in the whole portion of the number, you can't convert that to a DECIMAL(10,2)
. 如果整个数字中有8个以上的数字,则不能将其转换为DECIMAL(10,2)
。
For example: 例如:
select convert(decimal(10,2),'1000000000')
Try DECIMAL(12,2)
or use a VARCHAR(8)
. 尝试DECIMAL(12,2)
或使用VARCHAR(8)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.