【问题标题】:Crystal Reports: Record Selection SnafuCrystal Reports:记录选择混乱
【发布时间】:2012-08-22 02:06:30
【问题描述】:

我之前得到了一些非常好的帮助,我很感激。 我又遇到了一个唱片选择问题。

  1. 我有一个参数需要设置为结束日期。

  2. 我需要从名为 state_change 的表中提取结束日期之前的最新状态。

  3. 我需要从报告中排除在该时间段内未处于所需状态的任何记录。

state 当前设置为 state_change.new_state

( {@grouping} = "Orders" and rec_date < {?endDate} and {@state} in [0,2,5] )

OR

( {@grouping} = "Stock" and rec_date < {?endDate} and {@state} in [1,2,3,5,7] )

如果我可以运行 SQL 查询来提取此信息,它可能会起作用,但我不知道该怎么做。

基本上,我需要@state 是:

Select max(new_state)  
From state_change
where change_time < {?endDate}  

但在每个项目级别。

任何帮助将不胜感激。

【问题讨论】:

    标签: sql parameters crystal-reports record


    【解决方案1】:

    您可能需要使用带有参数的命令对象作为结束日期,或者创建参数化存储过程。命令对象将允许您输入您需要的所有 sql,例如在结束日期之前将结果与最大 newState 值连接起来:

    select itemID, new_state, rec_date, max_newState from
    (select itemID, new_state, rec_date from table) t inner join
    (Select itemID, max(new_state) as max_newState
        From state_change
        where change_time < {?endDate}  
        group by itemID) mx on t.itemid = mx.itemID and t.new_state = mx.max_newState
    

    我无法确定您的订单和库存分组是否在同一个表中,因此我不确定您需要如何通过正确的状态值来限制您的集合。

    【讨论】:

    • 它们实际上位于两个不同的表中,但我相信我可以将所有表合并并将两者分开。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 2015-12-26
    • 2014-05-11
    • 1970-01-01
    相关资源
    最近更新 更多