如果Excel中的语句 - Ms Access DB

时间:2012-10-10 14:48:26

标签: excel ms-access

任何人都可以建议以下IF语句的语法,

IIf
  (  Cur_Insert_Cost,
     Cur_Insert_Cost/Cur_Insert_Edges,
     Cur_Regrindable_Cost/(Cur_Regrinds_Possible+1)
   ) AS Cur_Cost_Edge_Regrind

以上行来自带有Ms-Access DB的Excel报告

我没有理解条件部分...... !!!

Cur_Insert_Cost,Cur_Insert_Edges,Cur_Regrindable_Cost ......等是列名

3 个答案:

答案 0 :(得分:4)

IIF是三元运营商。它由逗号分隔的三个部分组成

iif(expression, truepart, falsepart)

在你的情况下,它意味着:

if  Cur_Insert_Cost is not zero then 
    return the result of the expression Cur_Insert_Cost/Cur_Insert_Edges
else
    return the result of the expression Cur_Regrindable_Cost/(Cur_Regrinds_Possible+1)

结果将在查询中命名为Cur_Cost_Edge_Regrind

答案 1 :(得分:0)

测试是否为Cur_Insert_Cost 对于false或者任何Access计为false都被视为空。

所以这可能意味着 Cur_Insert_Cost = NULL,0,'',false(我想我忘记了一些替代方案)

正如您所看到的,第一部分使用的是和IIRC 应用于NULL的Cur_Insert_Cost会给出一个例外(但这只是我的记忆)

答案 2 :(得分:0)

声明说列Cur_Cost_Edge_Regrind的值是:

  • 如果Cur_Insert_Cost/Cur_Insert_Edges为真(或1)
  • Cur_Insert_Cost的结果
  • 如果Cur_Regrindable_Cost/(Cur_Regrinds_Possible+1)为FALSE(或0)
  • Cur_Insert_Cost的结果

希望有帮助...