Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Maximum record Post Reply Post New Topic
Author Message
mvonrose
Newbie
Newbie


Joined: 27 Aug 2013
Online Status: Offline
Posts: 2
Quote mvonrose Replybullet Topic: Maximum record
     Posted: 29 Aug 2013 at 12:24pm
Hello everyone,
 
Thank you for this site! Smile
 
I have a Crystal Report I inherited that I am revising.  It is using tables and not  Add a Command sql statements.
 
I need to access another table.  On this table, students have multiple records on a table, and I need to query the residency code in the correct record of the multiple records for each student.
 
For example:
 
Student ID    Effective Term Code   Residency Code
 
1111               201430                           X
1111               201320                           P
1111               201310                           X
1111               201420                           X
 
For student 1111 I need the record that has the maximum term<={?Term Code}.
 
The {?Term Code} is 201410.  Therefore, the correct record to pick up for this student is the 201320 term code record, because it is the maximum term code record <= 201410.
 
I can do this easily in sql, but can't seem to incorporate it into this Crystal Report. 
 
I've tried using Maxiumum in group selection formulas, record selection formulas, etc..., and nothing works.  I could have easily added it to a Command selection, if the report had been created using that as a selection source instead of linked tables.
 
There is alot in this report, so converting it to using a Command as selection source has been problematic, and I hate to start from scratch unless I absolutely have to.
 
Thanks for anyone's assistance!
 


Edited by mvonrose - 29 Aug 2013 at 12:25pm
IP IP Logged
iSing
Newbie
Newbie


Joined: 12 Mar 2013
Online Status: Offline
Posts: 22
Quote iSing Replybullet Posted: 29 Aug 2013 at 7:32pm
Hi mvonrose
 
This might seem obvious, but have you thought about using the Add Command to handle JUST the max record for the student?
 
If you combine this with your Term Code parameter in the command, you should get your maximum record for each student before your term code, eg in your example 201320
 
You could then link this with your tables like the rest of your data source.
You don't need to redo your entire report in SQL, just this bit.
 
IP IP Logged
mvonrose
Newbie
Newbie


Joined: 27 Aug 2013
Online Status: Offline
Posts: 2
Quote mvonrose Replybullet Posted: 04 Sep 2013 at 2:41am
iSing-
 
Thanks!  I had tried the Add Command before but I was using only a SELECT statement.
 
After your advice I went back and tried a few more things. 
 
What I needed was to do an INNER JOIN, then the SELECT.  That worked. Clap
 
My code in the Command was:
 
inner join
 (
    select s2.ID,
        max(s2.Term_Code) as max_term
        from student_table 2
        where s2.Term_Code <= '{?Term}'
        group by s2.ID
        ) s3
 on student_table = s3.ID                                                 
 and student_table.Term_Code = s3.max_term
 and student_table.Resd_Code = 'X'
 
The student_table above with no alias is joined to the other tables in the Crystal Report.   
 
Thanks again!!!  You were very helpful! Smile
 
IP IP Logged
iSing
Newbie
Newbie


Joined: 12 Mar 2013
Online Status: Offline
Posts: 22
Quote iSing Replybullet Posted: 04 Sep 2013 at 2:45pm
Hi mvonrose
Thanks - glad I could point you in the right direction.
 
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