Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:19:34+00:00 2026-06-10T02:19:34+00:00

I had received some really good help earlier, and I appreciate it. I have

  • 0

I had received some really good help earlier, and I appreciate it.
I have another record selection snafu.

  1. I have a parameter that I need to set as the end date.

  2. I need to pull the most recent state before the end date from a table titled state_change.

  3. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:19:36+00:00Added an answer on June 10, 2026 at 2:19 am

    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:

    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
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that's using git. When I received the repo, it had
Had a good search here but can't see anything that gets my mind in
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
We have received a WSDL from our client that we use to communicate with
Sorry to drag this up but I have had a good look around and
I've just come across some code that's confusing me slightly; there are really 2
I have some xml that is provided with generic attributes (name, type, etc), where
Since the way I had initially written my question received some down votes, and
SVN is giving me some trouble with a few .c files that I had
Had received a module from CCAVENUE and it was working fine with Magento 1.6.2...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.