Link to home
Start Free TrialLog in
Avatar of L_Potter
L_Potter

asked on

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.
Avatar of JayConverse
JayConverse
Flag of United States of America image

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
Avatar of peter57r
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.

ASKER CERTIFIED SOLUTION
Avatar of tickett
tickett
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

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