Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Sorting correct SQL Post Reply Post New Topic
Author Message
total1
Newbie
Newbie


Joined: 21 Jun 2012
Location: United States
Online Status: Offline
Posts: 3
Quote total1 Replybullet Topic: Sorting correct SQL
     Posted: 21 Jun 2012 at 8:22am
SQL2005 or 2008
 

Crystal Reports Xi

I have a Sales Analysis Report that generally works fine but it doesn't sort properly.  Apparently, I am getting the Sections by the field of Company Sales Rep [Company.SalesRepID] and not the field of Opportunity Sales Rep [Opportunity.SalesRepID].

 

Schema (generally):

Company:Contacts => 1:Many  [Company table has a SalesRepID field, as does the Contact table]

Company:Opportunities => 1:Many [Opportunity table has a SalesRepID field which defaults from the Company table but can be is changeable by the Sales Rep]

Contacts:Opportunities: => 1:Many

Opportunity:OpportunityJob => 1:1

 

User table has fields: UsersID with their Firstname, Lastname (for SalesRep and other users)

 

Crystal Report structure:

Group Header #1 (Lastname, Firstname from @RepName from Users table)

Group Header #2 OpportunityJob Create Date  [OpportunityJob.CreateDate]

Group Header #3 OpportunityID [Opportunity.OpportunityID]

Detail

 

Crystal Report output:

 

When I run the report I'm getting the Section 1 output correctly sorted by User table entry Lastname&Firstname.   That is, sales rep lastname, firstname like Adams, John then Burton, Richard then Cheek, David then Davis, Lee etc.

 
Here's the general CR layout after the page headers:

Group Header #1     : Doe, John

Group Header #2: is suppressed
Group Header #3: is suppressed
Detail                  : Date Sold  Job#     Account      Contact     Sale Amount

 

The SalesRep (Doe, John) fields are being extracted and sorted correctly from the User table.  I want to sort on the OpportunityJob.JobNumber in ascending order for each record that is associated with the Group Header #1 SalesRepID.   [Note: There is a SalesRepID field in the Opportunity table (Opportunity.SalesRepID] that contains the SalesRep internal key so I could select/filter on this Opportunity.SalesRepID field and then sort the OpportunityJob.JobNumber field.  Links appear to be setup fine.

How do I do this?
So, what am I doing wrong (or not doing!)?
 
What I currently see is the correctly sorted SalesRepID by lastname&firstname and then an improperly sorted JobNumber field (column) in the report as well as this JobNumber field NOT having the correct sales rep's initials to indicate that the job is his job.  That is, the JobNumber report column has a mixture of JobNumbers that don't correlate with the SalesRep's Lastname&Firstname from Section 1.

 

TIA

TIA
Tom
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 21 Jun 2012 at 9:16am
the fact that you are seeing jobs that are not for the worker likely indicates that the joins are not set to what you want.
that is one problem.
the other, sorting is done for details by using teh sort expert and setting the value for the field you want to sort on asc or desc.
fix your data set first, then go after the sort.
IP IP Logged
total1
Newbie
Newbie


Joined: 21 Jun 2012
Location: United States
Online Status: Offline
Posts: 3
Quote total1 Replybullet Posted: 21 Jun 2012 at 10:05am
Thanks for the response...
Now, how can I 'watch' or see/pause the execution of the report as it executes?
Is there a  'debug'  or 'link-test' I can do?
All I really get are the results of the entire database (2000) records once the report processes and I'm unable to fully debug the results DURING the process.
TIA
TIA
Tom
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 21 Jun 2012 at 10:16am
I am not aware of any such feature but that does not mean there is not something akin to your request.
However, usually with linking tables there is no way to debug it.
It either links or it does not. It is not smart enough to know if it linked to give you the data set you wanted.
From there is it more of an issue of did you get the links accurate for what you wanted and did you screw up the links in your select statement.
That being said, crystal has a 'feature' that allows you to add tables and not enforce the join. I have yet to find a use for this but it is something to be aware of.
When you link 2 (or more tables) in Crystal, the joins are not enforced unless you set them that way in the linking expert (per join) or when you use at least one field from both tables in the join inside the report (in any capacity).
 
I mention this as you might have joined items correctly but the crystal did not enforce the joins so your expected data set is not what you are working with.
IP IP Logged
total1
Newbie
Newbie


Joined: 21 Jun 2012
Location: United States
Online Status: Offline
Posts: 3
Quote total1 Replybullet Posted: 24 Jun 2012 at 4:10pm
Your suggestions were pretty much right-on.  I did make some changes in the linking but the main issue was the second Section and the record selection logic I had setup.  However, you caused me to review the specific areas that I needed to review and that generated the correction and the updates!
THANKS!!
TIA
Tom
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