错误:将表达式转换为数据类型nvarchar的算术溢出错误。
UPDATE [dbo].ForecastAccuracyKeyAccounts
SET ThreeMonthPercent = ((Actual - ThreeMonthForecast) / Actual) * 100, SixMonthPercent = ((Actual - SixMonthForecast) / Actual) * 100,
NineMonthPercent = ((Actual - NineMonthForecast) / Actual) * 100
WHERE Actual != 0
因为我用实际除以,所以我要确保实际不等于零。但是,当我在WHERE子句中添加该语句时,我无法摆脱该错误。
最佳答案
也许尝试ISNULL
UPDATE [dbo].ForecastAccuracyKeyAccounts
SET ThreeMonthPercent = ((Actual - ISNULL(ThreeMonthForecast,0)) / Actual) * 100,
SixMonthPercent = ((Actual - ISNULL(SixMonthForecast,0)) / Actual) * 100,
NineMonthPercent = ((Actual - ISNULL(NineMonthForecast,0)) / Actual) * 100
WHERE Actual != 0
关于sql - SQL算术溢出错误将表达式转换为数据类型nvarchar,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21686739/