sql - 运行查询时遇到除以零错误
问题描述
下面是我尝试使用 Microsoft SQL Server Management Studio 运行的查询:
update [SG report MPD-4153]
set [percent_paid] = (try_convert(float, [Savings This Season]) * 100 / try_convert(float, [Savings
Goal Amount]));
解决方案
您可以nullif()
在分母上使用:
update [SG report MPD-4153]
set [percent_paid] = (try_convert(float, [Savings This Season]) * 100
nullif(try_convert(float, [Savings Goal Amount], 0)
);
推荐阅读
- c# - 使用我的 NuGet 包编译项目的 .bond 文件
- javascript - Javascript重写
- c++ - 在菜单中显示加速键
- dataframe - 在 Julia 中使用人行横道翻译 Dataframe
- javascript - 是否可以从公共文件夹导入 vue 组件?
- algorithm - 在彼得森算法中启用标志之前设置转变量
- python - Python 密码学 Fernet.generate_key() 密钥长度
- android - 背景视频无法在 Android 上的 Chrome 上播放
- c++ - 如何将 std::string 用于 Const Char 参数
- react-native - React Native Animated.timing() 多个动画