如果条件不起作用,则访问 MS

MS access if condition doesn't work

我曾经有一个查询可以做很多事情,其中​​之一是告诉我每个员工的加薪情况。到期了吗?逾期了吗?对一个人来说太早了吗?

查询一直要求我输入参数,在问了这个问题后 removing "enter parameter value" in query MS access 我将一个查询分成了一堆,每个查询都建立在另一个之上,直到最后一个具有 if 条件。 一切都按照我想要的方式工作,除了 if 条件(以前工作正常!!!)

这是我的if条件

    Eligibility: IIf([MonthsSinceLastIncrease] < 24, IIf([MonthsSinceLastIncrease] >= 18
        AND [LastOfRatings] <= 2, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 15
            AND [LastOfRatings] = 1, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 9
                AND [MonthsSinceLastIncrease] < 15
                AND [LastOfRatings] = 1, "Eligible", IIf([MonthsSinceLastIncrease] >= 12
                    AND [MonthsSinceLastIncrease] < 18
                    AND [LastOfRatings] = 2, "Eligible", "ok")))), "OVERDUE")

加薪规则如下:

现在发生的情况是,对于一些员工,我只得到一条记录并且它是正确的,但对于一些员工,我得到两条记录,一条是正确的,另一条是错误的。现在我得到了 58 条记录,而不是 48 条记录(我以前在条件正常时得到的记录)。

这是整个查询的代码

SELECT IIf([MonthsSinceLastIncrease] < 24, IIf([MonthsSinceLastIncrease] >= 18
            AND [LastOfRatings] <= 2, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 15
                AND [LastOfRatings] = 1, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 9
                    AND [MonthsSinceLastIncrease] < 15
                    AND [LastOfRatings] = 1, "Eligible", IIf([MonthsSinceLastIncrease] >= 12
                        AND [MonthsSinceLastIncrease] < 18
                        AND [LastOfRatings] = 2, "Eligible", "ok")))), "OVERDUE") AS Eligibility
    ,MonthsSinceLastUpdateQ.LocalID
    ,MonthsSinceLastUpdateQ.LastOfRatings
    ,MonthsSinceLastUpdateQ.MaxOfDateOfUpdate
    ,MonthsSinceLastUpdateQ.MonthsSinceLastIncrease
FROM MonthsSinceLastUpdateQ
    ,DateOfUpdateQ
GROUP BY IIf([MonthsSinceLastIncrease] < 24, IIf([MonthsSinceLastIncrease] >= 18
            AND [LastOfRatings] <= 2, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 15
                AND [LastOfRatings] = 1, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 9
                    AND [MonthsSinceLastIncrease] < 15
                    AND [LastOfRatings] = 1, "Eligible", IIf([MonthsSinceLastIncrease] >= 12
                        AND [MonthsSinceLastIncrease] < 18
                        AND [LastOfRatings] = 2, "Eligible", "ok")))), "OVERDUE")
    ,MonthsSinceLastUpdateQ.LocalID
    ,MonthsSinceLastUpdateQ.LastOfRatings
    ,MonthsSinceLastUpdateQ.MaxOfDateOfUpdate
    ,MonthsSinceLastUpdateQ.MonthsSinceLastIncrease;

非常感谢您的帮助,请注意,我几乎不懂编码,只是在学习 MS Access,谢谢!

您查询中的表未链接。 Link 通过拖放在查询设计器中关联列,例如关系创建