How do I retrieve the most current date value?

Im working on a report in Crystal Reports XI, and I need to retrieve values from a field titled JE_SERVICE_CODE, which is a string field type.  Each JE_SERVICE_CODE value has a corresponding date value (the date it was entered) which is stored in a field titled JE_DATE_STAMP (both fields reside in the same table).   Is there a way to retrieve the JE_SERVICE_CODE value that is associated with the most current date value?  
Who is Participating?
Kurt ReinhardtConnect With a Mentor Sr. Business Intelligence Consultant/ArchitectCommented:
This is a pretty common requirement (show me the most recent/current records), but it's not handled very elegantly in Crystal Reports.  Before we can truly provide a solution, we need some questions answered:

1)  Are you reporting against a SQL-based database (SQL Server or Oracle, for example)?
2) Do you want to do this in SQL or within Crystal?

If you're trying to do this in Crystal Reports AND are reporting against a SQL-based database, the most efficient method is to create a SQL Expression field that identifies the most recent records.  You can then filter the report based on the expression field.  The benefit to doing this is that you pull only the records you need from the database rather than pulling all records and then suppressing them after the fact with conditional suppression or group select formulas.

I've attached a presentation with an example, starting on Slide 29.

If you want to do this entirely within SQL (if you're reports based on a view or command, for example), then we can help with writing a subquery for you.

If you need to do this in Crystal Reports AND are reporting against a PC-based database (like Access), then you probably need to sort records by date in descending order then either conditionally suppress all records where the date <> a formula for the max date value or do pretty much the same thing within the group selection criteria.
LinInDenverConnect With a Mentor Commented:
Hi there - depending on what you are looking for, it would be possible to create a parameter for the date field IF you know the date you are looking for. Or, you could filter the report to alway return today's date.

If it isn't quite that simple, I would start by sorting Descending on the date field, and see if I can do some conditional suppression on details not equal to the max value.

I don't know if this will help, but good luck!
mlmccConnect With a Mentor Commented:
One way would be to sort the data descending by date and display the first record.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.