Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: select first row Post Reply Post New Topic
Page  of 2 Next >>
Author Message
elie234
Groupie
Groupie


Joined: 21 Aug 2009
Online Status: Offline
Posts: 68
Quote elie234 Replybullet Topic: select first row
     Posted: 21 Sep 2009 at 8:03am
I have a report where I would like to select only the first row of a table. What is the best way to do that? Thanks.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 21 Sep 2009 at 8:06am
Depends on what is in the table.
Often tables have a PK that is incremental in value so a using teh minimum of that field would give you the first row only in that table.


Edited by DBlank - 21 Sep 2009 at 8:06am
IP IP Logged
elie234
Groupie
Groupie


Joined: 21 Aug 2009
Online Status: Offline
Posts: 68
Quote elie234 Replybullet Posted: 21 Sep 2009 at 8:11am
I think min would work in this case, but when I try to do a formula for minumum of the field in select expert it says that must be evaluated later. Is there some other way to select based on minimum?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 21 Sep 2009 at 9:06am

Usually that would be done at the source but you can do this in crystal in the Select Expert using Group Slection.

Go into the Select Expert Click on Show formula
Change your toggle option to Group Selection
Enter your group selection criteria here:
Minimum(table.field)=table.field
IP IP Logged
elie234
Groupie
Groupie


Joined: 21 Aug 2009
Online Status: Offline
Posts: 68
Quote elie234 Replybullet Posted: 21 Sep 2009 at 9:15am
This doesn't appear to be working. I still get multiple records even with the minimum formula.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 21 Sep 2009 at 9:17am
You will get multiple records if there are multiple rows with that value.
Are you joining any tables?
What is some sample data and what do you want it to to be after selection?
IP IP Logged
elie234
Groupie
Groupie


Joined: 21 Aug 2009
Online Status: Offline
Posts: 68
Quote elie234 Replybullet Posted: 21 Sep 2009 at 9:30am
Yes I am joining tables. This report consists of a bunch of different tables and subreports. It was displaying multiple records (8 when it should be 1). I have located that so far that without the table we are discussing I only get 4 records. So it is responsible for half of the duplication. For my purposes it is enough to select the first row in that table. I have been experimenting with just the table at hand in a blank test report with the group selection formula you recommended.
The weird thing is that in the test report it is now only displaying one detail row with the correct data for the minimum row but it is saying I still have two records. When I try the "real" report with this group selection formula I am still getting 8 records back.
IP IP Logged
elie234
Groupie
Groupie


Joined: 21 Aug 2009
Online Status: Offline
Posts: 68
Quote elie234 Replybullet Posted: 21 Sep 2009 at 9:33am
Maybe I should have been more clear as to what my problem is. I am getting ok data from this table. The problem is that I am getting multiple records from this table when I only need 1 and it is causing a bunch of other parts of the report to be duplicated. So I need the actual record selection of this table to be only 1 record. Does group selection formula only relate to what is displayed but not actual record selection?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 21 Sep 2009 at 9:45am
Group Selection in Crystal is a little different than the Record selection process.
Not sure how to best explain it...Record selection filters data after it is read from the DataBase but before it ends up in the report. Group selection has to let the data into the report, then group it then discard/exclude it. Does that help explain?
 
Likely your duplication is occuring by the table joins.
If you cannot biuld a process outside of crystal to limit the data you can try and use the Command functionality to build a SQL statement to try and do it inside crystal or you can use conditioanl suppression options to hide duplicate data and forumla fields or Running Totals to consitionally count or sum your values.


Edited by DBlank - 21 Sep 2009 at 9:46am
IP IP Logged
elie234
Groupie
Groupie


Joined: 21 Aug 2009
Online Status: Offline
Posts: 68
Quote elie234 Replybullet Posted: 21 Sep 2009 at 9:58am
If I understand you correctly- in this example:
For field X
Record 1= 5
Record 2= 6
If I use a group selection formula for the min of field X then the report will display only 5 but will actually be returning two records. Is that correct?
If so then I will still be getting two records and all of the other tables this table is linked to will also return two records and display their data twice (which I assume is what you mean that the duplication is the result of table joins).
I guess I could try an SQL statement or conditional suppression but it will be more tedious.
Is there any way to select based on record number?
IP IP Logged
Page  of 2 Next >>
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