Solved

Creating "left join" between subreport and report

Posted on 2010-08-26
4
972 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query Builder on BOXIR2 7 54
How to add a total 6 33
Crystal Reports 9 and Subreports 3 49
Crystal reports subreports as total of main report 13 52
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…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 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

11 Experts available now in Live!

Get 1:1 Help Now