[英]Nested IIF statement issue
Here is the whole statement:这是整个声明:
(IIF(i.AvgMonthlyCostOfSales<1,1,(IIF(i.AvgMonthlyCostOfSales)) * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE))<0,0,(i.AvgMonthlyCostOfSales) * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE) Loss
and getting error:并得到错误:
An expression of non-boolean type specified in a context where a condition is expected, near '('.
在预期条件的上下文中指定的非布尔类型的表达式,靠近 '('。
What I want to get is: if i.AvgMonthlyCostOfSales
value is less than one give me one, else:if multiplication of i.AvgMonthlyCostOfSales
and (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE)
is less than zero give me zero.我想要得到的是:如果
i.AvgMonthlyCostOfSales
值小于一,给我一个,否则:如果i.AvgMonthlyCostOfSales
和(i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE)
小于零,给我零。 otherwise give me the multiplied value.否则给我乘积。
Your parentheses were a bit crazy.你的括号有点疯狂。 Perhaps lay it out on separate lines for the condition, true and false:
也许将它放在单独的行中,用于条件真假:
IIF(
i.AvgMonthlyCostOfSales<1,
1,
IIF(
i.AvgMonthlyCostOfSales * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE)<0,
0,
i.AvgMonthlyCostOfSales * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE)
)
) Loss
If your SQLserver supports GREATEST it might be simpler to do:如果您的 SQLserver 支持 GREATEST,那么执行起来可能会更简单:
IIF(
i.AvgMonthlyCostOfSales<1,
1,
GREATEST(0, i.AvgMonthlyCostOfSales * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE))
) Loss
ps; ps; laying your original statement out with indentation makes it easy to see what went wrong:
用缩进列出你的原始语句可以很容易地看出哪里出了问题:
(
IIF(
i.AvgMonthlyCostOfSales<1,
1,
(
IIF(
i.AvgMonthlyCostOfSales
)
) * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE)
)<0,
0,
(i.AvgMonthlyCostOfSales) * (i.StockTurnoverCoefitient-n.OVER_SECOND_RANGE) Loss
it doesn't come back to indent level 0, and you have )
paired with IIF
, an IIF
that has no bool condition and no true/false etc它不会回到缩进级别 0,并且您已经
)
与IIF
配对,这是一个没有布尔条件且没有真/假等的IIF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.