Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Crystal Reports XI, from 2 SQL tables, MOST RECENT Post Reply Post New Topic
Author Message
lpremer
Newbie
Newbie


Joined: 24 Sep 2008
Location: United States
Online Status: Offline
Posts: 1
Quote lpremer Replybullet Topic: Crystal Reports XI, from 2 SQL tables, MOST RECENT
     Posted: 24 Sep 2008 at 11:03am
I have a SQL database that comes from a web entry form. There are two tables in my Crystal Report.
 
Users can enter updates on any/all fields whenever they want. The SQL database is keeping all updates. I just want to show the MOST RECENT update on my Crystal Report for every field. Not all fields will be updated at the same time.
 
All the fields that this will apply to are all in one table, called "CPlan_tblSurveyAnswer"-- all the field names that we need only the MOST RECENT values for are below.
 
I'm very new to SQL and Crystal, so looking at other answers to similar questions kinda confused me.
 
Where to start?
 
Thanks so much.
 
 
QuestionID Title FirstName LastName Telephone SurveyAnswer UpdatedDate
2 Title FirstName LastName Telephone SurveyAnswer 9/22/2008
2 Title FirstName LastName Telephone SurveyAnswer 9/23/2008
2 Title FirstName LastName Telephone SurveyAnswer 9/24/2008
3 Title FirstName LastName Telephone SurveyAnswer 9/22/2008
3 Title FirstName LastName Telephone SurveyAnswer 9/23/2008
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Sep 2008 at 1:23pm
If I understand you correctly, you want to display only the most recent record for your search criteria.  The most recent record will get you all of the most recent field changes.  To do this, you will have to use a command or a stored procedure instead of just the tables.
 
If you know SQL, it would probably be easiest to create a command.  It would look something like this:
Select <fields for your report>
from <tables for your report, including joins>
where <selection criteria for your report>
  and dbo.CPlan_tblSurveyAnswer.UpdatedDate =
    (Select max(GetDate.UpdatedDate)
     from dbo.CPlan_tblSurveyAnswer as GetDate
     where <links to the data above>)
Here's an example from something I've done:
Select l.lender_number, l.loan_number,
  l.inactive_ind, lh.posted_to_history_date
from loan as l
  inner join loan_history as lh on lh.history_key = l.history_key
where l.escrow_ind = 'YES'
  and lh.posted_to_history_date =
  (Select max(GetDate.posted_to_history_date)
   from loan_history as GetDate
   where GetDate.lender_number = l.lender_number
      and GetDate.loan_number = l.loan_number)
 
You then use the command in your report instead of the tables.
 
-Dell


Edited by hilfy - 24 Sep 2008 at 1:24pm
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