Error : Arithmetic overflow error converting numeric to data type varchar.
错误:将数值转换为数据类型varchar的算术溢出错误。
Getting error at this line why and what should be chnaged ?
在这一行得到错误为什么以及什么应该被chnaged?
CONVERT(VARCHAR(8),CONVERT(DECIMAL(8,4),((CurrentLoans.Price - PreviousLoans.Price) / PreviousLoans.Price) * 100))
2 个解决方案
#1
27
Here's at least one issue:
这里至少有一个问题:
CONVERT(VARCHAR(8),CONVERT(DECIMAL(8,4))
转换(VARCHAR(8),将(DECIMAL(8,4))
The Decimal(8,4)
indicates 8 numeric digits, 4 to the right of the decimal. This does NOT account for the actual decimal character, so you potentially have a value like:
十进制(8,4)表示8位数字,小数点右边4位。这不考虑实际的十进制字符,因此您可能具有如下值:
1234.5678
1234.5678
which is a valid Decimal(8,4)
but won't fit in a varchar(8)
.
这是一个有效的十进制(8,4),但不适合varchar(8)。
#2
1
I know this is an old post but I just wanted to say thanks. I was having this exact problem and what was most annoying was that it gave the error when selecting from a VIEW , but did not give the error when I used the select statement from the VIEW and pasted it and inserted it into a TEMP TABLE!!
我知道这是一个老帖子,但我只想说谢谢。我遇到了这个确切的问题,最令人讨厌的是它从VIEW中选择时出错,但是当我使用VIEW中的select语句粘贴并将其插入TEMP TABLE时没有给出错误!
example:
例:
select * from dvView --worked
select * from dvView where product = '5' --Broke!
--BUT
select * from #Temp_table_dvView --worked!
select * from #Temp_table_dvView where product = '5' --worked!
in the end, I had to changed a part in the view from
最后,我不得不改变视图中的一部分
select cast(productNumber as nvarchar(1), etc...
to
至
select cast(productNumber as nvarchar(2), etc...
and it worked.
它工作。
but weird that the error I got was
但奇怪的是,我得到的错误是
Arithmetic overflow error converting numeric to data type varchar.
instead of the one that reads
而不是读取的那个
Data would be truncated
or whatever...
管他呢...
food for thought.
值得深思。
#1
27
Here's at least one issue:
这里至少有一个问题:
CONVERT(VARCHAR(8),CONVERT(DECIMAL(8,4))
转换(VARCHAR(8),将(DECIMAL(8,4))
The Decimal(8,4)
indicates 8 numeric digits, 4 to the right of the decimal. This does NOT account for the actual decimal character, so you potentially have a value like:
十进制(8,4)表示8位数字,小数点右边4位。这不考虑实际的十进制字符,因此您可能具有如下值:
1234.5678
1234.5678
which is a valid Decimal(8,4)
but won't fit in a varchar(8)
.
这是一个有效的十进制(8,4),但不适合varchar(8)。
#2
1
I know this is an old post but I just wanted to say thanks. I was having this exact problem and what was most annoying was that it gave the error when selecting from a VIEW , but did not give the error when I used the select statement from the VIEW and pasted it and inserted it into a TEMP TABLE!!
我知道这是一个老帖子,但我只想说谢谢。我遇到了这个确切的问题,最令人讨厌的是它从VIEW中选择时出错,但是当我使用VIEW中的select语句粘贴并将其插入TEMP TABLE时没有给出错误!
example:
例:
select * from dvView --worked
select * from dvView where product = '5' --Broke!
--BUT
select * from #Temp_table_dvView --worked!
select * from #Temp_table_dvView where product = '5' --worked!
in the end, I had to changed a part in the view from
最后,我不得不改变视图中的一部分
select cast(productNumber as nvarchar(1), etc...
to
至
select cast(productNumber as nvarchar(2), etc...
and it worked.
它工作。
but weird that the error I got was
但奇怪的是,我得到的错误是
Arithmetic overflow error converting numeric to data type varchar.
instead of the one that reads
而不是读取的那个
Data would be truncated
or whatever...
管他呢...
food for thought.
值得深思。