Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Select only the lastest record Post Reply Post New Topic
Author Message
victoria61485
Newbie
Newbie


Joined: 14 Apr 2010
Online Status: Offline
Posts: 19
Quote victoria61485 Replybullet Topic: Select only the lastest record
     Posted: 03 Feb 2015 at 5:03am
Hello,

I have a report with an ID field (Command.ID) and a date field (Command.CommentDate) as well as several other fields. The ID field can be null. Each ID can have multiple Date fields. I want to pull only records with the latest date field. So for:

ID      Date
201     01/01/2015
201     01/15/2015
202     
203     01/01/2015
203     01/06/2015
204     12/31/2014
205     12/25/2014
205     12/28/2014
205     01/14/2015

I would want to return:
201     01/15/2015
202
203     01/06/2015
204     12/31/2014
205     01/14/2015

I want to return records where the date field is null as well. I have grouped on the Date field and sorted the group descending and that did not work. I also added the following code to the Group Select Expert: Command.CommentDate} = maximum({Command.CommentDate},{Command.Id})
This worked but eliminated records where the Date field is null. Is there a way to do this?

Thank you for any help!

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 03 Feb 2015 at 5:49am
Try this in the Select Expert:

IsNull({Command.CommentDate}) or
{Command.CommentDate} = maximum({Command.CommentDate},{Command.Id})

Another option would be to update the where clause in your command to include something like this:

(comments.CommentDate is null or
comments.CommentDate = (
Select max(c1.CommentDate) from comments as c1
where comments.ID = c1.ID))

This will filter it before it gets to the report.

-Dell
IP IP Logged
victoria61485
Newbie
Newbie


Joined: 14 Apr 2010
Online Status: Offline
Posts: 19
Quote victoria61485 Replybullet Posted: 03 Feb 2015 at 5:52am
Thank you! The first one worked!
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