MS Access过滤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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%', " ")
答案

使用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

以上是关于MS Access过滤的主要内容,如果未能解决你的问题,请参考以下文章

MS Access FileDialog 过滤器在原始负载上不起作用

MS.Access - 在 DoCmd.OpenReport [where 条件] 中使用 2 个过滤条件从表单打印报表

在 ms-Access 中使用组合框创建搜索表单

MS Access过滤

使用表单过滤交叉表查询 MS Access 2010

MS ACCESS 过滤器组合框所有选项