Solved

Crystal Reports - Link one field to two different tables

Posted on 2008-10-24
10
1,872 Views
Last Modified: 2011-09-20
We are using Crystal Reports 7 and I have three tables that I need to link together.  One table has production scrap information.  The other two have the production order information.  They are linked by the production order number.  One of the production order tables has all the past orders, the other one has the current orders.  The scrap table contains the info for all orders.  I would like to be able to link both of the order tables to the scrap table, so that if the production order number from the scrap table is not found in the current order table, it will pull it from the past order table.  Is this possible?  Thanks.

~bruno71
0
Comment
Question by:bruno71
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 22795959
You'll want to left join both production order tables to the scrap table, then use a formula to determine which production order number to show on the report.

If ISNULL(Current production order #) = TRUE then
Old Production Order #
ELSE Current production order #
0
 

Author Comment

by:bruno71
ID: 22796254
I tried that, but it is still only showing data from one or the other table.

~bruno71
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22796383
That is what you said you wanted...

"if the production order number from the scrap table is not found in the current order table, it will pull it from the past order table"
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 22796395
As stated you need to LEFT OUTER JOIN the tables

The SQL should look like

FROM ScrapTable LEFT OUTER JOIN CurrentProd ON ScrapTable.OrderID = CurrentProd.OrderID LEFT OUTER JOIN PastOrders ON ScrapTable.OrderId = PastOrders.OrderId

In the report just put fields from oth CurrentProd and PastOrders.  If one is NULL you wil not see the data.

mlmcc
0
 

Author Comment

by:bruno71
ID: 22796872
When I run the report, it either shows only data from the past orders table or only data from the current orders table.  It depends on which order number field I put in the details section (past or current).  If I put both (or use the formula as stated above) it just pulls from the last table it used.

Here is the SQL from the report...


SELECT

    GW_SCRAP."CutterOp", GW_SCRAP."Shift", GW_SCRAP."CutDate", GW_SCRAP."TotalPcsCut", GW_SCRAP."CutterScrap", GW_SCRAP."TotalScrap", GW_SCRAP."MachineNum", GW_SCRAP."Burn", GW_SCRAP."Lag", GW_SCRAP."Obstruction", GW_SCRAP."CutOff", GW_SCRAP."OpError", GW_SCRAP."Damage", GW_SCRAP."WireBreak", GW_SCRAP."DoveTail", GW_SCRAP."Thin", GW_SCRAP."Other", GW_SCRAP."Comment", GW_SCRAP."WaterSpots", GW_SCRAP."PoorFusion", GW_SCRAP."ColorContamination", GW_SCRAP."Camber",

    sfordfil_sql."ord_no",

    PPORDFIL_SQL."ord_no",

    IMITMIDX_SQL."drawing_release_no"

FROM

    { oj (("DATA"."dbo"."GW_SCRAP" GW_SCRAP LEFT OUTER JOIN "DATA"."dbo"."PPORDFIL_SQL" PPORDFIL_SQL ON

        GW_SCRAP."ProdOrdNum" = PPORDFIL_SQL."ord_no")

     LEFT OUTER JOIN "DATA"."dbo"."sfordfil_sql" sfordfil_sql ON

        GW_SCRAP."ProdOrdNum" = sfordfil_sql."ord_no")

     INNER JOIN "DATA"."dbo"."IMITMIDX_SQL" IMITMIDX_SQL ON

        sfordfil_sql."item_no" = IMITMIDX_SQL."item_no"}

WHERE

    GW_SCRAP."CutDate" >= 20080901 AND

    GW_SCRAP."CutDate" <= 20081031

ORDER BY

    GW_SCRAP."CutDate" ASC,

    GW_SCRAP."Shift" ASC,

    GW_SCRAP."CutterOp" ASC

Open in new window

0
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.

 
LVL 100

Expert Comment

by:mlmcc
ID: 22797291
That makes sense unless I am missing something.  I would suspect when an order is complete it gets moved from the Current table to the Past table.  Therefore an order only exists in one table.

mlmcc
0
 

Author Comment

by:bruno71
ID: 22797399
Sort of...actually we moved to a new type of production system.  So the old system orders are in the "old" table and the new and ongoing orders are in the "new" table.  The production order number is in the same format, but the old numbers are numbered around 125000 and the new ones start at 2000.
Is this just a limitation of version 7.0?

~bruno71
0
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 500 total points
ID: 22797486
I think you're going to have to change this to an outer join:
INNER JOIN "DATA"."dbo"."IMITMIDX_SQL" IMITMIDX_SQL ON
        sfordfil_sql."item_no" = IMITMIDX_SQL."item_no"}

LEFT OUTER JOIN "DATA"."dbo"."IMITMIDX_SQL" IMITMIDX_SQL ON
        sfordfil_sql."item_no" = IMITMIDX_SQL."item_no"}
0
 

Author Comment

by:bruno71
ID: 22797659
Awesome!  That worked!  I didn't realize that that table join would make a difference.  Thanks for your help.

~bruno71
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 22797906
Your welcome, glad it is working for you.

When you inner join a table that has been outer joined, you basically override the outer join and they both act as inners.
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
Crystal Reports - pulling data for fiscal year 2 47
Formatting a Crystal Report 2 47
Ignore parameter if no value entered 22 46
New and Previous Value in Crystal Report 8 53
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

16 Experts available now in Live!

Get 1:1 Help Now