我如何在MS Access查询中写这个?

时间:2013-08-01 17:00:41

标签: sql ms-access if-statement

以下是我将如何用C语言写的。

if(x < 50 && x < 0.125y)
    {
    return 0;
    }
else if(x < 50 && x >= 0.125y)
    {
    if(z >= 2a)
        {
        return 50;
        }
    }
else return b;

这是我的尝试,它只是一堆嵌套的ifs ......

IIf(([Est_Order_Qty]<50) And ([Est_Order_Qty]<0.125*[Quantity On Hand]),"0",IIf(([Est_Order_Qty]<50) And ([Est_Order_Qty]>=0.125*[Quantity On Hand]),IIf([Est_Order_Qty]<2*[Qty],"50",[Rounded_To_50])))

3 个答案:

答案 0 :(得分:2)

IIF((x < 50) AND (x < 0.125 * y), 0,
    IIF((x < 50) AND (x >= 0.125 * y) AND (z >= 2 * a), 50,
       b)

或您的尝试

IIf(([Est_Order_Qty] < 50) And 
    ([Est_Order_Qty] < 0.125 * [Quantity On Hand]), "0",
    IIf(([Est_Order_Qty] < 50) And 
        ([Est_Order_Qty] >= 0.125 * [Quantity On Hand]),
        IIf([Est_Order_Qty] < 2 * [Qty], "50", [Rounded_To_50]),
        [Rounded_To_50])
)

答案 1 :(得分:2)

尝试Switch

SWITCH(
x < 50 AND x < 0.125y, 0,
x < 50 AND x >= 0.125y AND z >= 2a, 50,
TRUE, b)

答案 2 :(得分:0)

如果我理解你的if语句,那么我的回答是:

    iif(x < 50 And x > 0.125y, "0", iif(x < 50 And x >= 0.125y, iif(2 >= 2a, 50, ""), b))

我相信就是这样。让我知道。