【问题标题】:SQL arithmetic overflow caused by negative numbers in part of formula公式部分负数导致的SQL算术溢出
【发布时间】:2016-09-13 16:00:43
【问题描述】:

Problem illustrated here

由于某些计算导致更新语句中的负数导致计算值导致算术溢出,但最终值应与声明的列一致。请帮忙!

【问题讨论】:

  • 请忽略我在问题说明中的拼写错误。公式为: Round((ExpMth - (CurrMth + .05) + 12 * (ExpYr - CurrYr)) / ((ExpMth - EffMth) + 12 * (Expr - EffYr)),6,1)
  • 不是显示的内容:Round((ExpMth - (CurrMth + .05) + 12 * (ExpYr - CurrYr)) / ((ExpMth - EffMth) + 12 * (Expr - EffYr)), 7,1)
  • 这适用于哪个 RDBMS?请添加标签以指定您使用的是mysqlpostgresqlsql-serveroracle 还是db2 - 或完全其他的东西。
  • 对不起... MS SQL Server 2012
  • 你的问题毫无意义。数字可以存储负值,因此这似乎不是您的问题。

标签: sql sql-server math stored-procedures sql-server-2012


【解决方案1】:

必须使用 cast 函数包装每个月列才能使其工作。

更新@RptTable SET EarningFactor = ROUND((ExpMth - (CurrMth + 0.5) + 12 * (ExpYr - CurrYr)) / ((cast(ExpMth as numeric) - cast(EffMth as numeric)) + 12 * (ExpYr - EffYr)),6 ,1)

【讨论】:

  • 很高兴你得到它。我还在试图弄清楚你的方程式
猜你喜欢
  • 1970-01-01
  • 2011-05-15
  • 2011-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多