• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I get the data for this one?

New Here ,
Apr 27, 2006 Apr 27, 2006

Copy link to clipboard

Copied

CF 7, SQL Server 2005
I will try and explain this as clearly as possible, let me know if I failed and I will attempt to clear it up.

The application keeps track of orders as they go through phases of production. Lets assume there are two phases of production, phase1 and phase2 with 3 statuses in each phase, new, open, complete. (depending on the phase an order can be in more than one phase at once.)

There is a phase_log table which is a reference table that has a row for every time the order's status changes.
Lets say the row in the phase_log table looks like this:

phase_logID | OrderID | PhaseID | StatusID | etc...

The main page will have a table for each phase, showing a list of the orders that currently have rows in the phase_log table for that phase. The kicker is, I only want to pull one row (the latest status change which will consequently be the highest status ID) for each order per phase.

once I pull the data I guess I can populate a struct or array, but I am new to this and I can't figure out how to get the query/s I need to get it.

Any help is appreciated,
Thanks
TOPICS
Advanced techniques

Views

198

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2006 Apr 27, 2006

Copy link to clipboard

Copied

LATEST
select phase_logid, orderid, phaseid, etc, max(statusid) status
from yourtables
where whatever
group by phase_logid, orderid, phaseid, etc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation