SQL SERVER 2008 nvarchar 转换 deciaml 失败(nvarchar to decimal)

转换数据发生

消息 8115,级别 16,状态 6,第 1 行
将 nvarchar 转换为数据类型 numeric 时出现算术溢出错误。

nvarchar 是带很长小数,直接转换成decimal 失败

解决方案:

先转换成float 再转换成decimal 或者int(去掉小数位)

  CAST(CAST(TRANS_CHARGE AS FLOAT) AS INT)

Why float?

  • no idea of precision or scale across all rows: float is the lesser evil perhaps
  • empty string will cast to zero for float, fails on decimal
  • float accepts stuff like 5E-02, fails on decimal

参考:

http://stackoverflow.com/posts/3790617/edit

原文地址:https://www.cnblogs.com/miralce/p/5002291.html