BOBJ 4.1 在一个预定义条件下使用来自两个未连接表的值

BOBJ 4.1 Use values from two not joined tables in one pre-defined condition

我使用一些预定义的条件来比较交易 table 的日期字段与 GETDATE() 函数来计算本月、今年、去年等的交易。

现在我需要创建一个额外的 table,其中我将有一组日期代表报告周期的开始和结束日期,例如当前年度报告的开始和结束日期,上一年报告的开始和结束日期等

此附加 table 和贸易 table 未加入。事实上,额外的 table 没有链接到任何东西。

我需要创建一组新的预定义条件,其中交易日期 table 将与新日期 table 的值进行比较,即我希望新条件如下所示

Trade.Date < ReportingDates.CurrentYearEndDate 
AND 
Trade.Date > ReportingDates.CurrentYearStartDate

条件验证正常,但不幸的是,当我尝试执行条件时出现 "The query cannot run because it contains incompatible objects. (IES 00008)" 错误。

您可以在预定义条件下使用子选择,例如:

trade.date between (select currentyearstartdate from reportingdates)
               and (select currentyearenddate from reportingdates)

因为reportingdates实际上没有加入任何东西,所以它不需要在宇宙结构中。这确实有一个缺点——从 table 的列表中看不出宇宙中实际需要它。

或者,您可以创建派生的 table,将 tradereportingdates 作为笛卡尔积连接起来。派生的 table 将包括来自两个 table 的所有列,因此您的条件将只是(假设派​​生的 table 被命名为 DT):

dt.date between dt.currentyearstartdate and dt.currentyearenddate

方法的缺点是 reportingdates 包含在 all 查询中,无论是否需要,并且SQL 可能有点难读。