如何根据另一个字段的值筛选MS Access字段

问题描述

我有一个Access查询,其中包含[Month]的字段和[Fiscal_Year]的另一个字段。我想过滤Month字段,以便仅在[Fiscal_Year] = 2021时返回[Month] 1,并在非Fiscal_Year 2021时返回所有[Month]

解决方法

(对不起,糟糕:将过滤后的月份中的null替换为TheMonth以获取月份) 计算字段可能是您要查找的字段。您可以在https://support.microsoft.com/en-us/office/add-a-calculated-field-to-a-table-14a60733-2580-48c2-b402-6de54fafbde3

上获得有关在网络上使用计算字段的更多指导。

假设您正在使用Access查询设计器这是一些示例数据,查询和查询结果。

enter image description here

enter image description here

enter image description here

这是计算出的字段FilteredMonth的详细信息,它不适合屏幕截图

FilteredMonth: IIf(Not ([table1].[FiscalYear]=2021) Or ([table1].[FiscalYear]=2021 And [table1].[TheMonth]=1),[table1].[TheMonth],Null)

这是生成的sql: '''' 选择Table1.TheMonth,Table1.FiscalYear,Table1.amount,IIf(Not([table1]。[FiscalYear] = 2021)或([table1]。[FiscalYear] = 2021 And [table1]。[TheMonth] = 1), [table1]。[TheMonth],Null)AS FilteredMonth 从表1; ''''

IIF或“仅当且仅当”是内置的访问功能,您可以查找它。