Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: LEFT OUTER JOIN 'overruled' by filter Post Reply Post New Topic
Author Message
dgadd
Newbie
Newbie


Joined: 08 May 2008
Location: Canada
Online Status: Offline
Posts: 3
Quote dgadd Replybullet Topic: LEFT OUTER JOIN 'overruled' by filter
     Posted: 08 May 2008 at 11:28am
Imagine a simple LEFT OUTER JOIN scenario:

SELECT person.Name, addr.Line1, addr.IsDefault
FROM Person person
LEFT OUTER JOIN Address addr ON person.PersonID = addr.PersonID
WHERE person.ID > 273

At the command line, I would expect to always get the person name, and optionally get the Line 1 and IsDefault if such a related record existed, eg:

John Wong   1234 Charwood Lane true
June Jones    4321 Happy St.          false
Mae June

When I place this in Crystal Reports (embedded version, Visual Studio 2005) I set the join settings in the Links tab to LEFT OUTER JOIN with Enforced Join set to 'Not Enforced'. So far, so good.

However, I also need to add one filter/formula:

{Address.IsDefault}

and this causes the problem:

My goal is for the report to show records 1 and 3 above. In other words, I only want Crystal Reports to perform the filter/formula when the Address record exists. Instead, it sees the lack of address as not meeting the filter/formula criteria and blocking row 3.

How do I get Crystal to allow row 3 while still maintaining the filter/formula?

Thanks,

David


Edited by dgadd - 08 May 2008 at 12:36pm
IP IP Logged
dgadd
Newbie
Newbie


Joined: 08 May 2008
Location: Canada
Online Status: Offline
Posts: 3
Quote dgadd Replybullet Posted: 08 May 2008 at 11:34am

I think I've found the solution:

ISNULL({Address.IsDefault}) OR {Address.IsDefault}
 
However, it has to be in THIS order.
 
If I reverse them:
 
{Address.IsDefault} OR ISNULL({Address.IsDefault})
 
then Crystal seems to 'INNER JOIN' the Address table based on that first criteria and all the rows that have null addresses are excluded.



Edited by dgadd - 08 May 2008 at 12:33pm
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 08 May 2008 at 2:01pm

This is not a Crystal "feature" it's the way that SQL works, you ALWAYS have to test for Is Null BEFORE you test for a value.  This is because null is not really a value, it's the absence of a value.  If you compare a null with some value, the result is null instead of false like you would expect. 

So, if {Address.IsDefault} is null, you're expression above evaluates to
 
null OR true
 
which then evaluates to null because you're comparing to null.
 
When evaluating an OR statement, the comparison processing stops when the first true condition is reached.  So, when you put the IsNull first, it evaluates to true and processing of the statement stops before you get to the comparison to null.
 
Make sense?
 
-Dell
 
IP IP Logged
dgadd
Newbie
Newbie


Joined: 08 May 2008
Location: Canada
Online Status: Offline
Posts: 3
Quote dgadd Replybullet Posted: 08 May 2008 at 2:55pm
Yes, that's helpful.
 
Thank you!
 
David
IP IP Logged
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