MS Access过滤

时间:2018-02-28 15:45:48

标签: sql ms-access

我正在尝试使用SQL视图和设计视图过滤访问中的以下数据。我基本上需要的是如果公司是公司2,那么我只想考虑ERP参考号“INV和EXP”的行。对于所有其他公司,我想包括所有内容。

Company Status  ERP Reference Number    Company Code    Supplier ID + Name
Company 1   Completed in Workflow   INV Finance 200350033 - ATRIUM STAFFING LLC
Company 1   Completed in Workflow   ss  Corporate   200350033 - ATRIUM STAFFING LLC
Company 1   Completed in Workflow   SS  Payroll 200350033 - ATRIUM STAFFING LLC
Company 1   Completed in Workflow   INV HR  200350033 - ATRIUM STAFFING LLC
Company 1   Completed in Workflow   SS  Finance 200350033 - ATRIUM STAFFING LLC
Company 2   Completed in Workflow   SS  Corporate   200350033 - ATRIUM STAFFING LLC
Company 2   Completed in Workflow   INV Payroll 200350033 - ATRIUM STAFFING LLC
Company 2   Completed in Workflow   ss  HR  200350033 - ATRIUM STAFFING LLC
Company 2   Rejected from Workflow  ss  Payroll 200350033 - ATRIUM STAFFING LLC
Company 3   Completed in Data Entry EXP HR  200152751 - KONE INC.
Company 3   Completed in Workflow   SS  HR  200364067 - ROTH BROS,INC
Company 3   Completed in Data Entry EXP HR  200152751 - KONE INC.
Company 3   Completed in Data Entry tsi Finance 200152751 - KONE INC.
Company 3   Completed in Data Entry TSI Corporate   200152751 - KONE INC.

这是我在SQL视图下的代码:

IIf([DFM report].[Company]="Company 1", [ERP Reference Number] like "%INV%' AND [ERP Reference Number] like '%EXP%', " ")

1 个答案:

答案 0 :(得分:0)

使用SWITCH检查Access中的不同条件(它类似于CASE的MS Access版本)。

SELECT *
FROM TABLE
WHERE (SWITCH(
    [DFM report].[Company]="Company 1" AND [ERP Reference Number] = "INV", 1,
    [DFM report].[Company]="Company 1" AND [ERP Reference Number] = "EXP", 1,
    [DFM report].[Company]<>"Company 1", 1, 
    TRUE, 0)) = 1