Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Maximum Value selection formula inquiry Post Reply Post New Topic
Author Message
formula_one
Newbie
Newbie


Joined: 30 Jun 2010
Online Status: Offline
Posts: 2
Quote formula_one Replybullet Topic: Maximum Value selection formula inquiry
     Posted: 30 Jun 2010 at 2:11am
hi
 
i am new in this forum and on crystal reports. I am currently using crystal reports 8.5 (old version already).
  I have already linked the tables ill be using on my report query. However I am having a hard time figuring out how to get the maximum value of a certain field in my report.
  My problem is that i need to know the updated address of a certain customer for my report. If theres a new address for said customer, the address table will increment its address_id field value just like the figure shown below which shows houston texas as john doe's current address.
 
address_id cust_code cust_name address
1 1001 John Doe san diego, california
2 1001 John Doe houston, texas
 
I already figured out this problem in sql by the following codes:
 
select *  from address where cust_code = 1001 and address_id in  (select max(address_id) from address where cust_code = 1001)
 
but cannot figure out how to do the same thing using crystal report's EDIT SELECTION FORMULA window. Any help will be very much appreciated.
 
thanks....
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 30 Jun 2010 at 2:26am
Hi
I think you should have command object in your Database Expert window when you initially created the report to select the tables.
*Click The connection and expand it to find Add Command,double click to enter the SQL
*In the Command window paste the SQL
as you have written in the post
 select *  from address where cust_code = 1001 and address_id in  (select max(address_id) from address where cust_code = 1001)
 
I would suggest to use the column names which are needed in the report instead of * to avoid entire table scan.
 
*Another suggestion would be to create view or stored proc at backend and use that instead of the tables.
 
* Then select the fields which you want in the report.
 
Cheers
Rahul


Edited by rahulwalawalkar - 30 Jun 2010 at 2:27am
IP IP Logged
formula_one
Newbie
Newbie


Joined: 30 Jun 2010
Online Status: Offline
Posts: 2
Quote formula_one Replybullet Posted: 30 Jun 2010 at 2:35am
i am really new in crystal reports. Can the solution not be done on EDIT SELECTION FORMULA WINDOW because i am not familiar with the command window thing....thanks....
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