Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1109
  • Last Modified:

Creating "left join" between subreport and report

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
L_Potter
Asked:
L_Potter
1 Solution
 
JayConverseCommented:
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
 
peter57rCommented:
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
 
tickettCommented:
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
 
mlmccCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now