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 ?
You're converting a 10 character number to a DECIMAL(10,2)
. That means up to 8 digits in the whole portion and 2 in the fractional. If there are more than 8 numbers in the whole portion of the number, you can't convert that to a DECIMAL(10,2)
.
For example:
select convert(decimal(10,2),'1000000000')
Try DECIMAL(12,2)
or use a VARCHAR(8)
.
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.