Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: get 6 most recent entries for a Part_ID Post Reply Post New Topic
Author Message
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Topic: get 6 most recent entries for a Part_ID
     Posted: 21 Jan 2009 at 11:15am
My table has hundreds of lines for each Part_ID
I would like to return only the 6 most recent Order_Date for EVERY Part_ID
 
Part_ID  Order_Date
ABC  4/31/08
ABC  11/5/07
ABC  6/3/07
ABC  10/1/06
ABC  8/4/06
ABC  5/5/05
XYZ  11/10/08
XYZ  4/3/02
etc. for EVERY Part_ID
 
 
I tried using Top N in Crystal group sort but it returned all rows for the Part_ID(s) having the Top 6 dates.
 
I'm open to using a SQL command
but where to add the most recent 6  for each Part_ID?
SELECT     PART_ID, ORDER_DATE, ORDER_QTY
FROM         MyTable
WHERE     (PART_ID <> 'NULL')
ORDER BY PART_ID, ORDER_DATE DESC
 
TIA
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 21 Jan 2009 at 11:26am
You could do this using a running count and a section suppression formula.
 
1.  Group on Part_ID and sort on Order_Date descending.
2.  Set up a Running Total that will count the number of records.  I would probably count the Order_Date, but not as a Distinct Count.  Set it to reset on change of the Part_ID group. I'm going to call it {#RecordCount}.
3.  Go to the Section Expert and select the section where your order data is being displayed.  Click on the button to the right of "Suppress" and enter the following:
 
{#RecordCount} > 6
 
This method won't actually reduce the number of records that are returned in the SQL, but it will only display the first 6 records of the part.
 
-Dell
IP IP Logged
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Posted: 22 Jan 2009 at 6:15am
Thank you,.
 
Works exactly as desired, and probably much faster than a Command would have.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum