Solved

Creating "left join" between subreport and report

Posted on 2010-08-26
4
962 Views
Last Modified: 2012-08-13
Hi all,

  I am unsure as to how exactly I can word this, so please bear with me.

  I have a report that kicks out some information regarding supervisors, followed by a subreport that outputs information about employees that each supervisor supervises.  What I'd like to do is more or less indicate, "If there are no employees currently supervised by this supervisor, don't display the supervisor."

  Coming from a SQL background, I think of it as essentially having two tables: one table lists supervisors, the other lists employees and their supervisors.  I would like to perform the equivalent of a left join from the employee table to the supervisor table (I suppose this could also be done as an inner join, if I wanted to be technical).

  The only method I have encountered is to create a shared variable that is populated in the detail section of the subreport when each employee is printed, and then look at this shared variable in the main report.  I am unsure as to whether or not this is the accepted method for performing such an action, or if there is a better way of doing so.  Any input on the matter would be greatly appreciated.
0
Comment
Question by:L_Potter
4 Comments
 
LVL 12

Expert Comment

by:JayConverse
ID: 33531560
Subreports are left-joined by default.  If there's no data retrieved, the subreport will be blank, and any shared variables will be blank or zero, depending on how you initialize them.  So, you need to do this:

1. Main - Formula that resets the shared variable
2. Subreport - Formula that may or may not set the variable
3. Main - Formula that reads and displays the variable
0
 
LVL 77

Expert Comment

by:peter57r
ID: 33531797
What you are asking for is absolutely NOT a left join equivalent - it is an INNER join - only display a value if there are matches on both sides of the join.

But that is really irrelevant to the Q..

To suppress a main form record when there is no subform record is difficult.

You can use a shared variable but not in the way you have probably tried to.
The value in the shared variable will only be processed by the subform when the subform runs.
In most reports the subreport follows the matching main report record.  That means the value in the shared variable has not been set when the main report record is printed (or it contains the value from the previous main report record).

To get over this you can add a copy or a cut down version of your subreport BEFORE any fields from the main record and this will allow you to count the subform records first.  That will allow you to conditionally suppress the main form record.  Obviously you don't want to see the copy so you size it very small and maybe format it white on white.

0
 
LVL 11

Accepted Solution

by:
tickett earned 500 total points
ID: 33532743
I can think of two nice easy ways to achieve the desired result (hopefully i've got it right :)

1) Don't display the supervisor name in the mane report. Pass it to the sub-report (using sub-report links) and display it in the sub-report header. It's then very easy to surpress the sub-report if no rows are returned.

2) Create a sql expression which counts the number of employees supervised by the supervisor and use it in the select expert.

Shout if you need more detail on either solution.

L
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 33535101
Method 1 works if there isn't much information to pass to the subreport.

Method 2 will work.

Is there any particular reason you havent included the subreport data in the main report?
The best way to handle this is to try to include the subreport data into the main report.

mlmcc
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now