Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: how2 choose most recently created record in a tbl Post Reply Post New Topic
Author Message
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Topic: how2 choose most recently created record in a tbl
     Posted: 01 Apr 2011 at 6:33am
I'm joining several tables (all inner joins) to get my result set. One of the tables contains status info about vehicles. 
 
Here's my problem: I need to use the information from the most recently created record in the vehicle-status table. 
 
Is there some way to use the record that has the max(create-date) value? In SQL proper, I'd do a subquery. How do I handle this in CR?
 
 
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 01 Apr 2011 at 7:13am
Depending on what you are doing with that date, the steps may be different and harder.

The simplest way to get the most recent date would be to use a maximum summary on the date field.

Another method would be to keep a variable that stores the most recent date by comparing it with other records as you are reading records from the DB. This variable would then be available before you begin printing records and should allow you to do more with it.
IP IP Logged
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Posted: 01 Apr 2011 at 7:55am
I kind of understand the logic behind your suggestion; but, I have no idea how to accomplish it. Could you provide code or pseudo-code (and tell me where to place it)? 
On my report, I need to display in the details line ONLY the most recent vehicle-status record fields--how could I do that with a maximum summary?
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 01 Apr 2011 at 8:24am
Only the most recent records?
Do you have a sample of what that might look like?

I'm thinking one record per group.
IP IP Logged
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Posted: 01 Apr 2011 at 10:20am
I have one vehicle-rental record, joined to three name records (renters), joined to two status records (that contain info regarding each rental event). 
 
I need to put on the report..
veh1     rented by persons 1&2     &the status from the most-recent rental
 
Thanks so much for your help!
 
 
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