0

我之前得到了一些非常好的帮助,我很感激。我还有另一个唱片选择混乱。

  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}  

但在每个项目级别。

任何帮助,将不胜感激。

4

1 回答 1

1

您可能需要使用带有参数的命令对象作为结束日期,或者创建参数化存储过程。命令对象将允许您输入所需的所有 sql,例如在结束日期之前将结果与 max 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

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

于 2012-08-21T18:06:30.853 回答