Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: eliminating lines with no match in second table Post Reply Post New Topic
Author Message
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Topic: eliminating lines with no match in second table
     Posted: 16 Mar 2009 at 1:49pm

I have a report of purchased items using tables PURCHASE and PART

 

Some PURCHASE.PART_ID are found in PART.ID others are not, because the part numbers are manually entered by the buyer for items like paper and pens.

 

 

When I use the Select Expert to state:

{PART.COMMODITY_CODE} <> "XYZ"

 

it not only eliminates those PURCHASE.PART_ID with PART. COMMODITY_CODE of “XYZ” it also eliminates all PURCHASE.PART_ID where a match is NOT found in PART.ID

 

I don’t really understand how you know if the table is “left” or “right”, but I tried both Left Outer and Right Outer Joins to no avail.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Mar 2009 at 6:49am
In SQL a left join 'says' to take all rows in the table on the left and the matching ones on the right, with unmatch rows on the right set to null.  Left and right took me a while but in SQL, the left would be TABLE1:
 
select * from TABLE1 left outer join table2 on table1.field=table2.field... 
 
Table1 is on the left...hence left outer join.  In Crystal I am guessing that if you set you tables up and then drag the linking field from the left table to the right table, and then set to the join type to outer, you get the left outer join, some one correct me if I am wrong (I use sql from stored procs exclusively in my reports).
 
I am not sure about the Select Expert statement, as the join is on purchase.part_id = part.id.  If there is not a match on the table with this condition, all values in one of the tables are going to be null (not found).
 
What table do you want all of the information for?  The other table may or may not contain matching information.  If you are looking to have all info from purchase, and you left outer join to part, any part that does match an entry in purchase will have null as all of the field values, so part.commodity_code = null for all entries in purchase that don't have 'matching' part.id.  So unfortunately, of course, they would be excluded.
 
Hope this helps...Hope I explained outer joins effectively
IP IP Logged
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Posted: 17 Mar 2009 at 12:06pm

I found a solution.

 

Using a Right Outer Join  (I still don’t know how you know if the table is on the left or right!)

 

I created a formula called @CommCodeValue

 

WhileReadingRecords;

Stringvar Message;

If IsNull({PART.COMMODITY_CODE}) or Trim({PART.COMMODITY_CODE}) = ""

Then Message := "No Code"

Else Message := {PART.COMMODITY_CODE}

 

 

Then my Select Expert

{@CommCodeValue} <> "XYZ"  works!
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