Crystal Reports

Table Linking in Crystal Reports

Overview
This document demonstrates the linking process in Crystal Reports (CR) 7 and
later. This document discusses linking for PC-type databases, ODBC linking and
frequently asked questions.

The linking processes are based on matching records, from a parent table (left
table) to records in a child table (right table). The match is based on whether the
value in the link field in the source record is identical to the value of the link
field in the searched records. The linking process is a form of record selection.

Contents
INTRODUCTION ............................................................................................ 3
GENERAL LINKING OVERVIEW ..................................................................... 3
Link Relationships........................................................................................3
One-to-one ......................................................................................................... 4
One-to-Many...................................................................................................... 4
ODBC LINKING .......................................................................................... 4
What is ODBC? ...........................................................................................4
SQL Join Types – ODBC connection ...........................................................4
Equal [=] join..................................................................................................... 5
Left Outer [=(+), *=] join .................................................................................. 5
Right Outer [(+)=, =*] join ................................................................................ 6
Greater Than [>] join ......................................................................................... 6
Less Than [<] join.............................................................................................. 7
Greater Than Or Equal [>=] join........................................................................ 7
Less Than Or Equal [<=] join ............................................................................ 8
Not Equal [!=, <>] join ...................................................................................... 8
HOW MULTIPLE TABLES AND MULTIPLE JOINS BETWEEN TABLES AFFECT THE
RECORD SET RETURNED .............................................................................. 9
Join Types Between Two Tables ..................................................................9
Two equal joins between two tables...........................................................10
Two Left Outer joins between two tables ...................................................10
Multiple Tables ..........................................................................................10
Equal Joins between tables A, B, and C........................................................... 11
Equal Join between tables A and B and Left Outer join between tables B and C
......................................................................................................................... 11
Left Outer Join between all three tables........................................................... 12
Left Outer Join between tables A and B and Equal Join between tables B and C
......................................................................................................................... 12

4/6/2004 1:49 PM Copyright  2002 Crystal Decisions, Inc. All Rights Reserved. Page 1

........... 18 CONTACTING CRYSTAL DECISIONS FOR TECHNICAL SUPPORT ...................... 17 Is it better to connect natively or through ODBC?...................... 18 What is smart linking? ................ Page 2 scr_pclinking......................................... 18 All link warnings were ignored and the report still works.............................................. 18 How do I know which fields I should link? ...........................................................................pdf ..................................................................................................................................13 The A to B Relationship ......... 18 What are those colored markers? ........................ 15 Look up both at the same time ....................................................................... Inc..............................................................................Crystal Reports Table Linking in Crystal Reports NATIVE (DIRECT) LINKING FOR PC-TYPE DATABASES ............................... 15 Look up all of one then all the others............................................. A to C Relationship.................... 16 Look up all combinations of the two................................14 The A to B to C Relationship....................... 16 FREQUENTLY ASKED LINKING QUESTIONS ............................... 18 What if I cannot link the fields?................. Is this OK? .... 12 Linking Between Two Tables ........................................................................... 17 Can you link tables from different databases? ........................... 19 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions...................... 13 Linking Between Three Tables....... 14 The A to B........................... All Rights Reserved.................................................................................................................................................

left-click the ‘Convert Database Driver’ option. verify what the text is beside the grayed out “From:” line. However. In other words. The available linking options in Crystal Reports differ with the type of connection to the database. NOTE VERIFY IF THE REPORT IS USING A NATIVE OR ODBC CONNECTION IN CR Under the Database command. The from table is considered the parent table (also referred to as the primary table or the left table) and the to table is the child table (also referred to as the lookup table or the right table). To report off more than one table in a single report. General Linking Overview Link tables to compare records from one database table to another database table.mdb.DLL” then the report is using an ODBC connection. If the text is “PDSODBC.Crystal Reports Table Linking in Crystal Reports Introduction Linking tables is not required when reporting off only one database table. the tables MUST be linked. These tables can be linked to match all the orders with the customer. The linking process defines the relationship between the database tables. Link Relationships When records are linked from one table to another table they will have a relationship type of either: • One-to-one • One-to-many NOTE The term "link" in Crystal Reports is equivalent to the term "relationship" in Microsoft Access. When linking tables. This is achieved by linking based on a field that is common to both tables.pdf .DLL” is another possible type of connection. If the text is anything else. Page 3 scr_pclinking. Inc. the linking options are different for ODBC and native (direct) connections. select the Orders table and the Customers table to create a new report. then the report is using a native (direct) connection. The relationship compares records between the tables. it is often necessary to report off more than one database table. the sample database that is shipped with Crystal Reports. * *”PDSOLEDB. Using tables from Xtreme. the link starts from one table to another. All Rights Reserved. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. Which table do you use as the parent table? This depends on the type of link relationship that is required to return the correct records. This is an OLE DB connection. In the ‘Convert Database Driver’ dialog box.

For example. For example. there are 8 different ODBC join types: • Equal Join • Left Outer • Right Outer • Greater Than • Less Than • Greater Than or Equal • Less Than or Equal • Not Equal 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.pdf . the Xtreme. Inc. This is considered to be a one- to-many relationship. For more information on ODBC. visit the following link: Open Database Connectivity (ODBC) Architecture - http://support.asp SQL Join Types – ODBC connection To link tables. For each Order ID there can be multiple Order ID’s in the Orders Details table.com/communityCS/TechnicalPapers/cr_odbc_arc hitecture. there can be multiple matching records in the lookup table (right). for every record in the primary table (left) there is only one matching record in the lookup table (right). For each Product Type ID there is only one Product Type Name. An application and a database driver communicate through a set of ODBC files known as the ODBC layer. SQL (Structured Query Language) to communicate to any type of database. All Rights Reserved.mdb database contains the Product and Product_Type tables. This is considered to be a one-to-one relationship.Crystal Reports Table Linking in Crystal Reports One-to-one In a one-to-one relationship between records in two linked tables. for every record in the primary table (left).pdf. The two tables are linked by the Order ID field. the Xtreme. One-to-Many In a one-to-many relationship between fields in two linked tables. Page 4 scr_pclinking. The ODBC layer uses a common language.mdb contains the Orders and the Orders_Detail tables. It is a standard developed by Microsoft through which different types of data can be accessed. These two tables are linkable on the common Product Type ID field.crystaldecisions. ODBC Linking What is ODBC? ODBC stands for “Open Database Connectivity”.

3. Also 5 Banana is not returned because there is no matching record in the first sample table. Each different join type affects record selection between two tables. All records where there is an exact match between the linked field values of two tables are returned. 2. Inc.Crystal Reports Table Linking in Crystal Reports To change the join type in Crystal Reports: 1. Record Set Returned From an Equal Join Color ID Color Color ID Fruit_Veg 1 Orange 1 Orange 2 Red 2 Apple 2 Red 2 Strawberry 4 Green 4 Lime 4 Green 4 Broccoli Left Outer [=(+). The two sample tables below represent the records. and left-click ‘Options’. Notice that 3 blue from the left hand table is now returned. as the record is not from the left table. which is represented by an arrow. In the ‘Visual Linking Expert’ dialog box. Sample Database Tables Color_ID Color Color_ID Fruit_Veg 1 Orange 1 Orange 2 Red 2 Apple 3 Blue 2 Strawberry 4 Green 4 Lime 4 Broccoli 5 Banana Equal [=] join The record set from an equal join includes all the records where the linked field value in both tables is an exact match. Page 5 scr_pclinking. right-click on the link. In the ‘Link Options’ dialog box. select one of the available SQL join types. no matching records are returned for 3 Blue. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. All Rights Reserved.pdf . Notice that there are no blue fruits or vegetables in the second sample table therefore. It also includes a row for every record in the primary (left) table for which the linked field value has no match in the lookup (right) table. as they are stored in the database. Under the Database command. 5 Banana from the right hand table is still not returned. The two sample tables are used to demonstrate how each join type affects record selection. *=] join The record set from a left outer join includes all the records in which the linked field value in both tables is an exact match. left-click the ‘Visual Linking Expert’ option.

Records are returned when the Color ID of the LEFT table is greater than the Color ID of the RIGHT table. It also includes a row for every record in the lookup (right) table for which the linked field value has no match in the primary (left) table.Crystal Reports Table Linking in Crystal Reports Record Set Returned From a Left Outer Join Color ID Color Color ID Fruit_Veg 1 Orange 1 Orange 2 Red 2 Apple 2 Red 2 Strawberry 3 Blue 4 Green 4 Lime 4 Green 4 Broccoli Right Outer [(+)=. Inc. Notice that 5 banana is returned because it is in the right hand table but 3 blue is not included in the record set because there is no matching record in the right table. Record Set Returned From a Greater Than Join Color ID Color Color ID Fruit_Veg 2 Red 1 Orange 3 Blue 1 Orange 3 Blue 2 Apple 3 Blue 2 Strawberry 4 Green 1 Orange 4 Green 2 Apple 4 Green 2 Strawberry 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.pdf . Page 6 scr_pclinking. All Rights Reserved. =*] join The record set from a right outer join includes all the records in which the linked field value in both tables is an exact match. Record Set Returned From a Right Outer Join Color ID Color Color ID Fruit_Veg 1 Orange 1 Orange 2 Red 2 Apple 2 Red 2 Strawberry 4 Green 4 Lime 4 Green 4 Broccoli 5 Banana Greater Than [>] join The record set from a greater than join includes all records in which the linked field value from the primary table is greater than the linked field value in the lookup table.

Record Set Returned From Greater Than or Equal To Join Color ID Color Color ID Fruit_Veg 1 Orange 1 Orange 2 Red 1 Orange 2 Red 2 Apple 2 Red 2 Strawberry 3 Blue 1 Orange 3 Blue 2 Apple 3 Blue 2 Strawberry 4 Green 1 Orange 4 Green 2 Apple 4 Green 2 Strawberry 4 Green 4 Lime 4 Green 4 Broccoli 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.pdf . All Rights Reserved. Page 7 scr_pclinking. Records are returned when the Color ID of the LEFT table is greater than or equal to the color ID of the RIGHT table. Records are returned when the Color ID of the LEFT table is LESS than the Color ID of the RIGHT table. Inc. Record Set Returned From a Less Than Join Color_ID Color Color_ID Fruit_veg 1 Orange 2 Apple 1 Orange 2 Strawberry 1 Orange 4 Lime 1 Orange 4 Broccoli 1 Orange 5 Banana 2 Red 4 Lime 2 Red 4 Broccoli 2 Red 5 Banana 3 Blue 4 Lime 3 Blue 4 Broccoli 3 Blue 5 Banana 4 Green 5 Banana Greater Than Or Equal [>=] join The result set from a Greater Than Or Equal join includes all records in which the linked field value in the primary table is greater than or equal to the linked field value in the lookup table.Crystal Reports Table Linking in Crystal Reports Less Than [<] join The result set from a Less Than join includes all records in which the linked field value in the primary table is less than the linked field value in the lookup table.

Records are returned when the Color ID of the LEFT table is LESS than or Equal to the Color ID of the RIGHT table. All Rights Reserved. <>] join The result set from a Not Equal join includes all records in which the linked field value in the primary table is not equal to the linked field value in the lookup table. Page 8 scr_pclinking.Crystal Reports Table Linking in Crystal Reports Less Than Or Equal [<=] join The result set from a Less Than Or Equal join includes all records in which the linked field value in the primary table is less than or equal to the linked field value in the lookup table.pdf . Records are returned when the Color ID of the LEFT table is NOT EQUAL to the Color ID of the RIGHT table. Inc. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. Record Set Returned From Less Than or Equal To Join Color_ID Color Color_ID Color 1 Orange 1 Orange 1 Orange 2 Apple 1 Orange 2 Strawberry 1 Orange 4 Lime 1 Orange 4 Broccoli 1 Orange 5 Banana 2 Red 2 Apple 2 Red 2 Strawberry 2 Red 4 Lime 2 Red 4 Broccoli 2 Red 5 Banana 3 Blue 4 Lime 3 Blue 4 Broccoli 3 Blue 5 Banana 4 Green 4 Lime 4 Green 4 Broccoli 4 Green 5 Banana Not Equal [!=.

pdf . as they are stored in the database.Crystal Reports Table Linking in Crystal Reports Record Set Returned From Not Equal Join Color ID Color Color ID Fruit_Veg 1 Orange 2 Apple 1 Orange 2 Strawberry 1 Orange 4 Lime 1 Orange 4 Broccoli 1 Orange 5 Banana 2 Red 1 Orange 2 Red 4 Lime 2 Red 4 Broccoli 2 Red 5 Banana 3 Blue 1 Orange 3 Blue 2 Apple 3 Blue 2 Strawberry 3 Blue 4 Lime 3 Blue 4 Broccoli 3 Blue 5 Banana 4 Green 1 Orange 4 Green 2 Apple 4 Green 2 Strawberry 4 Green 5 Banana NOTE The most common join types are the Equal and Left Outer. Sample Database Tables Table 1 Table 2 First Name Last Name First Name Last Name Jack White Jack White Elizabeth Black Mary Black Jane White Jim Green John Brown John Brown Mary Black Laura Green 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. Page 9 scr_pclinking. The two tables below represent records. Inc. How multiple tables and multiple joins between tables affect the record set returned Join Types Between Two Tables The following demonstrates how different join types affect the record set returned. All Rights Reserved.

It is not possible to have two different kinds of joins between two tables. For example if you had two tables that each contained a first name and last name field.pdf . Record Set Returned From Two Left Outer Joins FirstName LastNameFirstNameLastName Jack White Jack White Elizabeth Black Jane White John Brown John Brown Mary Black Mary Black Laura Green NOTE If there are two links between two tables. For example. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. with two equal joins. then.Crystal Reports Table Linking in Crystal Reports Two equal joins between two tables The more joins there are between two tables. Multiple Tables As more tables and more links are added. it becomes more and more difficult to understand how the linking will affect the record set. when the join type for one link is changed. the join type for the other link will automatically change to the same type of link. Record Set Returned From Two Equal Joins FirstName LastName FirstName LastName Jack White Jack White Mary Black Mary Black John Brown John Brown Two Left Outer joins between two tables When there are two left outer joins between tables. Inc. the more restrictive the record set returned. The following example examines the record sets returned when there is linking between three tables. if you had two tables that each contained a first name and last name field and they were linked with two left outer joins. All Rights Reserved. Page 10 scr_pclinking. the record set returned is also more restrictive. then ALL the records from the first table would be returned but only records where the first AND last name matched in the second table would return. you would get back records where the first name AND the last name matched in both tables.

Notice that “green” and “lime” from the first two tables are not returned because there is no match in the third table. with the above three-table scenario. records are returned that have matching values in all three tables.pdf . records return when there are matching records that meet all the equal joins specified. and C When there are equal joins connecting multiple tables. Record Set Returned From Equal Joins Connecting Multiple Tables Colors ID Color Colors ID Fruit_Veg Fruit_Veg_ID Fruit_veg ID Food 2 Red 2 Apple 2 2 Apple crumble 1 Orange 1 Orange 1 1 Marmalade 2 Red 2 Strawberry 3 3 Strawberry shortcake Equal Join between tables A and B and Left Outer join between tables B and C The following is the record set returned when there is an equal join between tables A and B and a left outer join between tables B and C Notice that now the green lime and broccoli are returned even though there is no matching food in table C. Inc. B.Crystal Reports Table Linking in Crystal Reports Sample Database Tables Table A Table B Table C Color ID Color Colors ID Fruit_Veg Fruit_Veg_ID Food Fruit_veg ID 1 Orange 1 Orange 1 Marmalade 1 2 Red 2 Apple 2 Apple crumble 2 3 Blue 2 Strawberry 3 Strawberry shortcake 3 4 Green 4 Lime 4 Banana cream pie 6 4 Broccoli 5 Peach cobbler 10 5 Banana 6 Equal Joins between tables A. Record Set Returned From Equal Join Between A and B and a Left Outer Join Between B and C Colors ID Color Colors ID Fruit_Veg Fruit_Veg_ID Fruit_veg ID Food 1 Orange 1 Orange 1 1 Marmalade 2 Red 2 Apple 2 2 Apple crumble 2 Red 2 Strawberry 3 3 Strawberry shortcake 4 Green 4 Lime 4 4 Green 4 Broccoli 5 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. For example. Page 11 scr_pclinking. All Rights Reserved.

This is because table A is the Driving table and the Left Outer join between Table A and Table B excludes this data. Record Set Returned From Left Outer Joins Between Tables A. For more information on Linked and Unlinked Subreports. Notice that 3 blue is returned even though there is no match in either table B or C. The linked subreport will give you the equivalent of a left outer join link. All Rights Reserved. one would have to create a main report based on table A and then a linked subreport that is based on tables B and C.com/communityCS/TechnicalPapers/scr_subrepor ts.pdf. B and C (A to B. visit the following link: http://support.pdf . Page 12 scr_pclinking. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.asp Native (Direct) Linking for PC-type Databases This section describes how Crystal Reports defines file links for PC-type databases using a native (direct) connection. The join type created when connecting natively to a PC-type database is a Left Outer join.crystaldecisions. B and C Colors ID Color Colors ID Fruit_Veg Fruit_Veg_ID Fruit_veg ID Food 1 Orange 1 Orange 1 1 Marmalade 2 Red 2 Apple 2 2 Apple crumble 2 Red 2 Strawberry 3 3 Strawberry shortcake 3 Blue 4 Green 4 Lime 4 4 Green 4 Broccoli 5 Left Outer Join between tables A and B and Equal Join between tables B and C This linking scenario resulted in the following error: This means that the Microsoft driver is unable to interpret the SQL for this linking scenario. Notice that “banana” and “banana cream pie” is NOT returned. Inc.Crystal Reports Table Linking in Crystal Reports Left Outer Join between all three tables The following is the record set returned when there is a left outer join between tables A. B to C). In order to create a report that uses this linking.

00 2 Linda Johnson 2 Project 3 5. Oracle.000. When no further matches are found in the child table.000.000. Lotus Notes. In this case the link field is EmpID. from the parent table has only one corresponding match in the child table (B).000. In the example above. Fox Pro.000. Paradox.Crystal Reports Table Linking in Crystal Reports Examples of PC-type databases are: • Microsoft (MS) Access. Page 13 scr_pclinking.000.00 Crystal Reports (CR) concatenates the first record from the parent table (A) to each record containing a link field of identical value in the child table (B).00 2 Linda Johnson 2 Project 3 5. Visual FoxPro NOTE Connecting Natively to an SQL. Each record from the parent table is treated as a unique record regardless of whether it really is. Pervasive. using the data in this example. All Rights Reserved.pdf .type database using SQL-type native (direct) database drivers defaults to an Equal join.00 2 Linda Johnson 2 Project 3 10.00 Crystal Reports (CR) creates virtual records by taking each record containing a specific value in the link field in table A and connecting it to a corresponding record containing an identical value in the link field in table B. Informix. Examples of these client/server databases are: DB2. Sample Database Tables Table A Table B EmpID EmpName EmpID Project Amount 1 Kim Smith 1 Project 1 1.00 2 Project 3 10. Inc. However. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. the following record set will be returned to the report: Record Set Returned From Linking Two Identical Fields From Table A and Table B EmpID EmpName EmpID Project Amount 1 Kim Smith 1 Project 1 1. Act!.000.00 2 Linda Johnson 2 Project 4 10. EmpID “1”. SQL Server Linking Between Two Tables The A to B Relationship The two sample database tables are used in the following linking examples. When linking from Table A to Table B.000. CR moves to the next record in the parent table. Goldmine. Consequently there are 3 virtual records created for Linda Johnson. Btrieve.00 2 Project 4 10. Visual DBase. This process is repeated for all the remaining records in the parent table. EmpID“2” has 3 matches.

00 2 Class 5 2 Linda Johnson 2 Project 4 10.000.000.000.00 2 Class 5 2 Linda Johnson 2 Project 3 10.00 2 Class 4 2 Project 3 10. Sample Database Tables Table A Table B Table C EmpID EmpName EmpID Project Amount EmpID Class 1 Kim Smith 1 Project 1 1.00 2 Class 4 2 Linda Johnson 2 Project 3 10.00 2 Class 5 2 Project 4 10.Crystal Reports Table Linking in Crystal Reports EmpID “2”.000. A third table. to give: A -> B ->C The three sample database tables are used in the following linking examples.00 2 Class 6 2 Class 7 Crystal Reports creates virtual records that follow along every valid “link” on EmpID that matches in all 3 tables.000. is simply added as a final link to the A to B combination. This is the result of concatenation of records from the parent table to the child table.000.000.000.00 2 Class 6 2 Linda Johnson 2 Project 4 10. Page 14 scr_pclinking. All Rights Reserved. Linking Between Three Tables The A to B to C Relationship In an A to B to C relationship.00 2 Class 7 2 Linda Johnson 2 Project 3 10.pdf .000. Table B and Table C Table A Table B Table C EmpID EmpName EmpID Project Amount EmpID Class 1 Kim Smith 1 Project 1 1.00 2 Class 4 2 Linda Johnson 2 Project 4 10.00 2 Class 7 2 Linda Johnson 2 Project 4 10. “C”. when only one source record really exists in the actual database (in Table A). the rules for creating virtual records are the same as those used in the A to B relationship. Inc.000.000.000. The following would be the record set returned to the report in this type of relationship: Record Set Returned From Linking Three Identical Fields From Table A.00 1 Class 3 2 Linda Johnson 2 Project 2 5.000.00 2 Class 7 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.00 2 Class 4 2 Linda Johnson 2 Project 2 5.000.000.00 2 Class 5 2 Linda Johnson 2 Project 2 5.00 2 Class 6 2 Linda Johnson 2 Project 3 10.00 2 Class 6 2 Linda Johnson 2 Project 2 5.00 1 Class 3 2 Linda Johnson 2 Project 2 5.000.000.

type databases using a native connection. three occurrences in Table B. If a match is found. the number of “ detail records” returned to the report can be much greater than the total number of actual records contained in the tables/databases. not SQL. and the number of valid “ links” between them. In the event that a blank is found from both look-up tables. a blank record will be appended to the virtual record. In this example. if no match is found. The A to B. Since there is only one occurrence of EmpID 1 in Tables A. The number of virtual records created for a given source record is equal to the number of records in the table that has the maximum number of records matching the source record. Crystal Reports would return thirteen (13) detail records. Since there are one occurrence of EmpID 2 in Table A. Page 15 scr_pclinking. Table C contains the maximum 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. A to C Relationship This section demonstrates record set returned from the linking of three tables using an A to B. there are a total of nine (9) records in all three tables. the total number of virtual records created for EmpID 2 is 1 x 3 x 4 = 12. Crystal Reports then searches Table C for a match to the source record. then this record is appended to the virtual record (which now contains the source record from Table A and either a match from Table B. multiply the number of occurrences of that record in each of the tables in the link together (A x B x C). and 4 occurrences in Table C. and C. Otherwise. As in the example above. A to C relationship.Crystal Reports Table Linking in Crystal Reports To determine the number of virtual records returned for a particular source record. Look up both at the same time Selecting the option ‘Look up both at the same time’. All Rights Reserved. Inc. or a blank). it will append a blank record to the source record. If a match is found. Crystal Reports will append the matching record from Table B to the source record from Table A. There are three options available when setting up the linking relationship in Crystal Reports: • Look up both at the same time • Look up all of one then all the others • Look up all the combinations of the two CAUTION This is a relationship available only to PC-type databases. the resultant virtual record will not be included and the read process for the next source record from Table A. the total number of virtual records created is 1 x 1 x 1 = 1. However. initiated. Crystal Reports starts with the source record in Table A and looks for a match in Table B. NOTE Depending on how you link tables/databases. but on the report. B.pdf .

Record Set Returned From Linking A to B. and then appends a match found in Table C to create the virtual record. and looks up matches in Table B.000. This is done for each match found in Table C. Inc.000.000. This is then appended to each matching record from Table C. A to C Using the ‘Look up both at the same time’ Option EmpID EmpName EmpID Project Amount EmpID Class 1 Kim Smith 1 Project 1 1.000.000.00 2 Class 5 2 Linda Johnson 2 Project 4 10.00 1 Class 3 2 Linda Johnson 2 Project 2 5. Crystal Reports looks for matches to the source record in Table C.00 2 Class 6 2 Linda Johnson 2 2 Class 7 Look up all of one then all the others Selecting the option ‘Look up all of one then all the others’. The total number of virtual records created per source record is determined by summing together the number of matched records for the source record in each table. The process is repeated for each match found in Table B. All Rights Reserved. It then appends blank to the created virtual record. Crystal Reports takes the source record from Table A.00 2 2 Linda Johnson 2 Project 3 10.000.pdf .Crystal Reports Table Linking in Crystal Reports number of matching records for EmpID 2. which is 4. so the number of virtual records created is 4. Crystal Reports appends the first record from Table B that matches the source record from Table A.00 2 2 Linda Johnson 2 2 Class 4 2 Linda Johnson 2 2 Class 5 2 Linda Johnson 2 2 Class 6 2 Linda Johnson 2 2 Class 7 Look up all combinations of the two Selecting the ‘Look up all combinations of the two’ option. Record Set Returned From Linking A to B. Page 16 scr_pclinking.00 1 1 Kim Smith 1 1 Class 3 2 Linda Johnson 2 Project 2 5. It concatenates a match from Table B to the source record to create a virtual record. In this example the number of virtual records for EmpID “2” is 4+3=7.000. After reading through Table B completely. It appends a copy of the source record to a blank field.00 2 Class 4 2 Linda Johnson 2 Project 3 10. A to C Using the ‘Look up all of one then all the others’ Option Table A Table B Table C EmpID EmpName EmpID Project Amount EmpID Class 1 Kim Smith 1 Project 1 1. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.00 2 2 Linda Johnson 2 Project 4 10.000.

000. the second database can be brought in as a linked subreport. it is impossible to have an A to B to C link.Crystal Reports Table Linking in Crystal Reports Once all matching records from Table C have been exhausted.pdf . Frequently Asked Linking Questions Can you link tables from different databases? It is not recommended to link tables from different databases in the same report. concatenates the two records. All Rights Reserved.00 2 Class 4 2 Linda Johnson 2 Project 3 10.000.000.00 2 Class 6 2 Linda Johnson 2 Project 4 10.000. you could set up A to B.00 2 Class 7 2 Linda Johnson 2 Project 4 10. Record Set Returned From Linking A to B.00 1 Class 3 2 Linda Johnson 2 Project 2 5.00 2 Class 5 2 Linda Johnson 2 Project 2 5.asp 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. Tables within the same database can be linked but errors may occur when tables from different databases are linked.crystaldecisions.00 2 Class 4 2 Linda Johnson 2 Project 4 10.000. visit the following links: • Connecting to Multiple Data Sources In a Report - http://support.00 2 Class 5 2 Linda Johnson 2 Project 4 10. Page 17 scr_pclinking.000.00 2 Class 5 2 Linda Johnson 2 Project 3 10.00 2 Class 6 2 Linda Johnson 2 Project 3 10. If the fields must be linked.00 2 Class 6 2 Linda Johnson 2 Project 2 5. In this example. Instead.com/library/kbase/articles/c2008838. from the table on Page 3.000. and appends a copy to each matching record from Table C. Crystal Reports returns to Table B to select the next record that matches the source record.000. A to C and use ‘Look up all combinations of the two’ to achieve the same results. Inc. A to C Using the ‘Look up all combinations of the two’ Option Table A Table B Table C EmpID EmpName EmpID Project Amount EmpID Class 1 Kim Smith 1 Project 1 1.00 2 Class 7 Notice that the above result set is identical to an A to B to C link with no Lookup Options.000.000. With this lookup option. the number of virtual records created equals the number of matching records in Table A x matches in Table B x matches in Table C.00 2 Class 7 2 Linda Johnson 2 Project 3 10. Linda Johnson. For more information on this topic.000. there are 1 x 3 x 4 = 12 virtual records.000.00 2 Class 4 2 Linda Johnson 2 Project 2 5.000. Why does the option ‘No Lookup’ yield the same results as the option ‘Look up all combinations of the two’? Answer: When there is no common field between Table B and Table C.

What are those colored markers? Colored markers are seen in the Visual Linking Expert when there is a Native connection to the database. The markers represent indexed fields and primary keys that can be linked. With Native Connections. There is no special relevance to the color of the markers other than if you have a composite index. it is possible to use a linked subreport instead. All link warnings were ignored and the report still works. These are identifiable by the colored markers beside them.com/communityCS/TechnicalPapers/scr_sub reports.pdf . In general the linking allowed with an ODBC connection is more flexible (allowing more join types). With an ODBC connection.crystaldecisions. Which connection is preferred is also database specific.pdf. Smart linking is not necessarily the correct linking required for your desired result set. The report may run but may be unstable and/or return erroneous or no data.asp Is it better to connect natively or through ODBC? There are advantages and disadvantages to both types of connections. What is smart linking? Smart linking is the default linking that Crystal performs if the ‘Smart Linking:” option is enabled in the ‘Options’ | ‘Database’ tab under the ‘File’ command. If tables are linked incorrectly. How do I know which fields I should link? It is important that you understand the structure of your database.Crystal Reports Table Linking in Crystal Reports • Linked and unlinked subreports - http://support. The ODBC data sources must be correctly configured and set up first. Page 18 scr_pclinking. Is this OK? You should not ignore the link warnings. What if I cannot link the fields? If the fields are not linkable in the Visual Linking Expert dialog box. it is probable that erroneous or no data will return. A linked subreport will give the equivalent join type of a Left Outer Join. All Rights Reserved. 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions. Inc. A native connection requires less setup and may be faster because it connects directly to the database. the markers will be the same color. they must be of the same data type and length. Smart linking links fields of the same name and same data type and length. If you are not sure which fields to link. only indexed fields can be linked. Some databases will only allow one type of connection. check with your Database Administrator. in order to link fields.

crystaldecisions. Self-serve Support: http://support. Inc.crystaldecisions. All Rights Reserved.com/contact/support. Page 19 scr_pclinking.Crystal Reports Table Linking in Crystal Reports Contacting Crystal Decisions for Technical Support We recommend that you refer to the product documentation and that you visit our Technical Support web site for more resources.asp 4/6/2004 1:49 PM Copyright  2002 Crystal Decisions.asp Telephone Support: http://www.com/support/answers.pdf .crystaldecisions.com/ Email Support: http://support.