[英]Arithmetic overflow error converting varchar to data type numeric
Hi i have a query below which creates insert script for me.嗨,我在下面有一个查询,它为我创建了插入脚本。 the column TotalPremiumValue has
datatype Decimal(5,2)
. TotalPremiumValue 列的
datatype Decimal(5,2)
。 when i execute my query i am getting the following error: Arithmetic overflow error converting varchar to data type numeric.当我执行查询时,出现以下错误:将 varchar 转换为数字数据类型的算术溢出错误。 can anybody help me?
有谁能够帮我?
SELECT 'IF NOT EXISTS(SELECT 1 FROM Lkup.TotalPremium WHERE [TotalPremiumValue]= '''+[TotalPremiumValue]+''')
INSERT INTO Lkup.TotalPremium ' +
'(' +
'[TotalPremiumValue],' +
'[EffectiveDate]' +
')' +
'VALUES (' +
CASE WHEN [TotalPremiumValue] IS NULL THEN 'NULL' ELSE CONVERT(VARCHAR(40), [TotalPremiumValue]) END + ', ' +
CASE WHEN [EffectiveDate] IS NULL THEN 'NULL' ELSE 'CONVERT(DATETIME, ' + master.sys.fn_varbintohexstr (CONVERT(BINARY(8), [EffectiveDate])) + ')' END + ', ' +
')'
FROM Lkup.TotalPremium
Thanks谢谢
Please try the below query请尝试以下查询
SELECT
'IF EXISTS(SELECT 1 FROM Lkup WHERE [TotalPremiumValue] = ' + CONVERT(varchar(50), [TotalPremiumValue]) + ')
INSERT INTO Lkup ' +
'(' +
'[TotalPremiumValue]' +
')' +
'VALUES (' +
case when CONVERT(varchar(50),[TotalPremiumValue]) IS NULL then 'null' else CONVERT(varchar(50),TotalPremiumValue) end +
')'
FROM Lkup
Perhaps try recasting the result as a decimal(5,2)?也许尝试将结果重铸为小数(5,2)? I added the call into a portion of your code and pasted the section below.
我将调用添加到您的代码的一部分并粘贴了下面的部分。 You could also shrink that varchar(40) down to a varchar(6), which would hold all 5 numbers plus the decimal point.
您还可以将 varchar(40) 缩小为 varchar(6),它将保存所有 5 个数字加上小数点。
'VALUES ( CAST(' +
CASE WHEN [TotalPremiumValue] IS NULL THEN 'NULL' ELSE CONVERT(VARCHAR(40), [TotalPremiumValue]) END + ' AS DECIMAL(5,2)), ' +
CASE WHEN [EffectiveDate] IS NULL THEN 'NULL' ELSE 'CONVERT(DATETIME, ' + master.sys.fn_varbintohexstr (CONVERT(BINARY(8), [EffectiveDate])) + ')' END + ', ' +
')'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.