十进制转换错误(算术溢出)错误 [英] decimal conversion error (arithmatic overflow) error

查看:169
本文介绍了十进制转换错误(算术溢出)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i得到

hi all,

i am getting

Arithmetic overflow error converting varchar to data type numeric.

this错误。

代码脚本在下面

this error.
the code script is below

Declare @Amount Decimal(18,4)

Declare @strSql VARCHAR(MAX)

SET @strSql =''

SET @strSql = 'UPDATE TABLE1 SET col1='+@Amount+' where id=1'
print @strSql 

--EXEC(@strSql)





i我正在使用exec,因为where条件是动态的。表格列也有相同的类型。



请帮帮我。



谢谢



i am using exec because the where condition is dynamic.the table column is also has the same type.

Please help me out.

Thanks

推荐答案

你需要解决两件事:

1)给@Amount一个值 - 目前它是null,所以它赢了;工作得很好。

2)将@Amount转换为VARCHAR



Two things you need to fix:
1) Give @Amount a value - at present it is null, so it won;t work too well.
2) Convert @Amount to a VARCHAR

Declare @Amount Decimal(18,4)
Declare @strSql VARCHAR(MAX)
SET @strSql =''
SET @Amount=0.0
SET @strSql = 'UPDATE TABLE1 SET col1='+CONVERT(VARCHAR, @Amount)+' where id=1'
print @strSql


OriginalGriff是正确的。



了解更多关于这个问题,请参考 - Msg 8115 - 转换数字的算术溢出错误数据类型varchar。 [ ^ ]和 SQL SERVER - FIX:错误:msg 8115,Level 16,State 2,Line 2 - 算术溢出错误转换表达式数据类型 [ ^ ]。
OriginalGriff is correct.

To know more about this issue, refer - Msg 8115 - Arithmetic overflow error converting numeric to data type varchar.[^] and SQL SERVER – FIX : Error : msg 8115, Level 16, State 2, Line 2 – Arithmetic overflow error converting expression to data type[^].


这篇关于十进制转换错误(算术溢出)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆