I had received some really good help earlier, and I appreciate it.
I have another record selection snafu.
-
I have a parameter that I need to set as the end date.
-
I need to pull the most recent state before the end date from a table titled state_change.
-
I need to exclude any records from the report who are not in the required states at that period in time.
state is set currently to be 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] )
If I could run a SQL query to pull this information, it would probably work, but I cannot figure out how to do it.
Essentially, I need @state to be:
Select max(new_state)
From state_change
where change_time < {?endDate}
but on a per item level.
Any help would be appreciated.
You’ll probably need to use a command object with a parameter for your end date, or create a parameterized stored procedure. The command object will allow you to enter all the sql you need, like joining your results with the max newState value before the end date:
I can’t tell if your orders and stock groupings are in the same table, so I’m not sure how you need to limit your sets by the correct state values.