Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Sorry but my Left Outer Join is kicking my butt Post Reply Post New Topic
Page  of 2 Next >>
Author Message
ronhextall
Newbie
Newbie


Joined: 19 Aug 2010
Online Status: Offline
Posts: 5
Quote ronhextall Replybullet Topic: Sorry but my Left Outer Join is kicking my butt
     Posted: 19 Aug 2010 at 6:50am
Lets say I have a Customer File and a Customer Maintenance file.
 
Customer File has the following fields:
Customer Number
Customer Name
Customer Address
 
 
Customer Maintenance has the following fields:
MaintCustNumber
MaintType
MaintDate
MaintDescription
 
I want to join the two files so that I see every Customer File record even in their are no matching Customer Mainteance records.  So I figure this is perfect for a left outer join. 
Other factors:
 I also am prompting for a customer number and MaintDate via parameter fields.  The customer number is option, they could enter nothing to get all of them.
I also only want Maintenance records that MaintType = "1".
 
In my link options I use a "left outer join","Not enforced", and "=".  ( have messed with all the "Enforce Join" options with no luck).
 
After reading several other posts here dealing with left out join pain my selection criteria looks like this:
 
if hasValue({?CustomerNumber}) then
    {CustomerMaster.CustomerNumber} = {?CustomerNumber}
    and
    (   ({CustomerMaintenance.MaintDate} >= {?From Date}) or (isnull({CustomerMaintenance.MaintDate})))
    and
    (   ({CustomerMaintenance.MaintType} = "1") or (isnull({CustomerMaintenance.MaintType})))
 
Sorry the post is so long but I wanted to make sure I covered everything.  This works fine if their are matching records.  When their are no Customer Maintenance records of MaintType = "1" I would still like to see the Customer Number, Name, and address on the report but I get nothing.
 
If somebody could offer this Crystal green horn I would be very happy. 
 
p.s. I took off the "else" portion of my selection criteria, I figured I would put it back in once I got it working.  Just assume I always put a customer number in.


Edited by ronhextall - 19 Aug 2010 at 6:52am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Aug 2010 at 6:57am
do you want to see
all customers
customers that meet your condition OR have never had a maintenance record?


Edited by DBlank - 19 Aug 2010 at 6:57am
IP IP Logged
ronhextall
Newbie
Newbie


Joined: 19 Aug 2010
Online Status: Offline
Posts: 5
Quote ronhextall Replybullet Posted: 19 Aug 2010 at 7:03am

I want all customers, I want the ones that have matching record(s) in the maintenance file (that have a Mainttype of "1"). I also want the customers that have no matching record at all.

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Aug 2010 at 7:07am
that is 2 different things as you are filtering out records that match but do not meet your criteria.
Can you write a view or stored proc or do you have to do this all in crystal?
IP IP Logged
ronhextall
Newbie
Newbie


Joined: 19 Aug 2010
Online Status: Offline
Posts: 5
Quote ronhextall Replybullet Posted: 19 Aug 2010 at 7:11am
Ok, I will drop the maintType issue.  So my Select expert basically looks like this now:
 
if hasValue({?CustomerNumber}) then
    {CustomerMaster.CustomerNumber} = {?CustomerNumber}
    and
    (   ({CustomerMaintenance.MaintDate} >= {?From Date}) or (isnull({CustomerMaintenance.MaintDate})))
I still don't have any luck getting some output when there is no matching record.
 
Thanks for your input.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Aug 2010 at 7:15am
No you will likely have to do a conditional suppression rather than selection if you cannot pass the params to a stored proc or a command.
the problem is that the select statment is always applied AFTER the join so if you filter rows from one table you are also fitering teh matching row (customer) from the otehr table.
Does that help?


Edited by DBlank - 19 Aug 2010 at 7:15am
IP IP Logged
ronhextall
Newbie
Newbie


Joined: 19 Aug 2010
Online Status: Offline
Posts: 5
Quote ronhextall Replybullet Posted: 19 Aug 2010 at 7:23am
Originally posted by DBlank

No you will likely have to do a conditional suppression rather than selection if you cannot pass the params to a stored proc or a command.
the problem is that the select statment is always applied AFTER the join so if you filter rows from one table you are also fitering teh matching row (customer) from the otehr table.
Does that help?
 
 
 
what would my selection expert look like if I dropped it to the minimum required and did the rest of the work using conditional suppression? 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Aug 2010 at 7:26am
your selection would be blank
all of it would be in suppression
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Aug 2010 at 7:57am
outer join as you were
group on the customer.customernumber
i think your supression formula on the detail section will be:
NOT(
(hasValue({?CustomerNumber}) and {CustomerMaster.CustomerNumber} = {?CustomerNumber})
and
({CustomerMaintenance.MaintDate} >= {?From Date}
and
{CustomerMaintenance.MaintType} = "1"
)


Edited by DBlank - 19 Aug 2010 at 8:00am
IP IP Logged
ronhextall
Newbie
Newbie


Joined: 19 Aug 2010
Online Status: Offline
Posts: 5
Quote ronhextall Replybullet Posted: 19 Aug 2010 at 8:37am

Suppression will probably work and I will go at it from that angle for a while.  Just seems to me that if you could do it in the selection criteria the report would be more explicit when it comes to maintenance going forward.  Drilling down in a bunch of supression statements in my opinion is a little too implicit.

Of course I am fairly new to Crystal so I will hold off too much damning commentary until my feet get a little more wet.

 



Edited by ronhextall - 19 Aug 2010 at 8:40am
IP IP Logged
Page  of 2 Next >>
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum