Print Page | Close Window

Sort on field in Subreport

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6832
Printed Date: 27 Apr 2024 at 7:35am


Topic: Sort on field in Subreport
Posted By: Vack
Subject: Sort on field in Subreport
Date Posted: 23 Jun 2009 at 9:26am
I have a subreport that returns a date on my main report. Is it possible to sort on the value that is returned by my subreport?



Replies:
Posted By: Takesen
Date Posted: 23 Jun 2009 at 12:26pm

Just an idea, I believe it should work...

if you create a shared variable (would be eiter datetimevar or datevar)

make it
 
shared datetimevar := {datetime_field}
 
throw this into your main report and group by it. you can suppress the group header and footer if you don't want to see them.


Posted By: lockwelle
Date Posted: 24 Jun 2009 at 6:20am
absolutely should work.


Posted By: Vack
Date Posted: 24 Jun 2009 at 9:31am
When I go to group it the formula field is not an option to group by. That Doesn't seem to work.


Posted By: lockwelle
Date Posted: 24 Jun 2009 at 10:43am
OK, in the subreport you have a formula like:
shared datetimevar  aVar := {table.field}
 
in the main report you have a formula like:
shared datetimevar aVar
 
if this is the setup, I don't know, since you should be able to group on the formula name that is located in the main report.  I group on formulas all the time.


Posted By: DBlank
Date Posted: 24 Jun 2009 at 12:10pm

Is this an issue of evaulation processes?

Can one sort or group on a field that has not been determined until the records are printed?


Posted By: Takesen
Date Posted: 24 Jun 2009 at 1:38pm
If Dblank's case is correct,
You need to make a copy of the subreport and place it in the report header. (You cannot suppress this subreport, instead make it as small as possible and all the fonts white).
 
You'll pull you're shared variable off that, and it should be able to be used without any issues.
 
-Takesen


Posted By: lockwelle
Date Posted: 25 Jun 2009 at 5:46am
Yeah, DBlank, you might be right.  Hadn't thought of the subreport aspect, as I generally don't use them, but depending on how the subreport/report is structured Takesen's solution may not work either as the fields may not be available.  I think that the report can be suppressed, but the problem is going to be that the report....
 
Guys, I think that we have been barking up the wrong tree, could be wrong, but the subreport is returning a date...just a date and he wants to sort on it...that's not really grouping, but at the same time, you can't sort the main report's data based on a subreport value, and placing the subreport in the header isn't do it either.
 
The most efficient way to accomplish this is to have the sort criteria in the main report's data...either stored proc/view or join the data (which might cause duplicates).  Of course I vote for stored procs, because they give you the flexibility to do this sort of this, as well as bring in the data for the subreport all in one row.  then it is just a matter of displaying, but at the very least a sort date field could be added to the row.
 
Now the reason that I changed my mind is of how I think of Crystal working....it reads a row of data for the main report/formats it, then if it needs to it reads the subreport data/formats it, and reads the next row...DBlank is right, it doesn't know the sort value until tool late.



Print Page | Close Window