我有这个代码
declare @termtomonths float
set @termtomonths=120/365.00
set @termtomonths= round(@termtomonths,2,1)*12
select power(1-(1+0.11/12.00), -3.84)
当我运行它时,它返回错误
Msg 3623, Level 16, State 1, Line 6
An invalid floating point operation occurred.
在 MS EXCEL 中尝试这个公式,它有效
=1-(1+0.11/12)^-3.84
预期结果
0.034432865
如何将这个 Excel 公式转换为 SQL 公式?
谢谢
最佳答案
您的 SQL 表达式有误。 要获得与 Excel 中相同的效果,您应该执行以下操作:
SELECT 1 - POWER(( 1 + 0.11 / 12.00 ), -3.84);
这将为您提供:0.0344326
请注意,SQL 中的 POWER 函数内有 1 -
,但 Excel 中没有。
该错误也会导致您获得浮点错误,因为您的基数不能为负。
关于sql-server - SQL 提升到错误 "An invalid floating point operation occurred."的幂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36171062/