使用日期之间的 iif 函数进行查询以提供 X

Making a query with iif function using between for dates to provide X

我正在使用 MS access 创建一个查询,以确定出生日期是否介于另一个 table 中找到的开始日期和结束日期之间,如果是,请提供在同一 [=17] 中找到的符号=] 作为开始和结束日期。

我不知道为什么每个生日都会得到 2 个结果。
任何人都可以帮助每个出生日期只有一组结果吗?
我附上了下面的代码。

SELECT [TBL_IndicativeData_AllPpts].ID, [TBL_IndicativeData_AllPpts]![DOB] AS DOB, IIf([TBL_IndicativeData_AllPpts]![DOB] Between [TBL_Mapping_Funds_TargetDate]![Earliest Birth Date] And [TBL_Mapping_Funds_TargetDate]![Latest Birth Date],[TBL_Mapping_Funds_TargetDate]![Fund Symbol],"Null") AS TargetDateFund

FROM TBL_Mapping_Funds_TargetDate, [TBL_IndicativeData_AllPpts]
WHERE (((IIf([TBL_IndicativeData_AllPpts]![DOB] Between [TBL_Mapping_Funds_TargetDate]![Earliest Birth Date] And [TBL_Mapping_Funds_TargetDate]![Latest Birth Date],[TBL_Mapping_Funds_TargetDate]![Fund Symbol],"Null"))<>"null"));

这将 return 符合条件的记录:

SELECT 
    [TBL_IndicativeData_AllPpts].ID, 
    [TBL_IndicativeData_AllPpts]![DOB],
    [TBL_Mapping_Funds_TargetDate]![Fund Symbol]
FROM 
    [TBL_IndicativeData_AllPpts],
    [TBL_Mapping_Funds_TargetDate]
WHERE 
    [TBL_IndicativeData_AllPpts]![DOB] Between 
        [TBL_Mapping_Funds_TargetDate]![Earliest Birth Date] And 
        [TBL_Mapping_Funds_TargetDate]![Latest Birth Date]

但是,如果 TargetDate table 具有重叠的日期范围,您可能会收到欺骗。如果是这样,请尝试 SELECT DISTINCT ....