Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating "left join" between subreport and report

Posted on 2010-08-26
4
Medium Priority
?
1,069 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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 101

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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