table.INTERSECT Function

Syntax

V Intersect(), Specify the required values in the Intersect dot variable, then use the following command:

Arguments

Intersect.t_db

Type "C". The secondary table filename.

Intersect.o_file

Type "C". The resulting table filename.

Intersect.m_key

Type "C". Contains expression strings that describe how fields or combinations of fields form the linking key in the primary table.

Intersect.t_key

Type "C". Contains expression strings that describe how fields or combinations of fields form the linking key in the secondary table.

Intersect.m_filter

Type "C". A character filter expression that selects records from the primary table to use in the intersect.

Intersect.t_filter

Type "C". A character filter expression that selects records from the secondary table to use in the intersect.

Intersect.delete_o_dd

Type "L".

.T. = Overwrite the resulting table's data dictionary, if it exists.
.F. = Do not overwrite the resulting table's data dictionary, if it exists.
Intersect.m_count

Type "N". The number of fields in the resulting table.

Intersect.m_field1 ... Intersect.m_fieldN

Type "C". Variables for each field that specify the table name and field name. Each field name string must include the table name or alias as a prefix (i.e., "table->field"). Field names from the Secondary table must have an "@" in front of the table or alias name.

Description

Create a new table that is the intersection between the table and a secondary table.

Discussion

The <TBL>.INTERSECT() method is a high-level utility that you use to create a new table by merging the records from a Primary table with matching records from a Secondary table. The new table contains only those records from the Primary table that have a matching record in the Secondary table. The Primary table must be an open table that is identified by the object pointer, <TBL>. The Secondary Table is specified through its the variable intersect.t_db. The joined records are saved in the new table named by the intersect.o_file variable. Records in the Secondary table are matched to records in the Primary table through linking keys. The Primary Key Expression and Secondary Key Expression parameters contain expression strings that describe how fields or combinations of fields from each table form the linking keys. The Intersect operation is performed over the selection of records that satisfy the Primary and Secondary Filter Expressions.

Example 

This script shows how two tables that have one or more similar fields can be intersected to include only records for each primary record (Customer) that match a secondary record (inv_head).

dim tbl as P
tbl = table.open("c:\a5\a_sports\customer")
intersect.t_db = "c:\a5\a_sports\inv_head.dbf"
intersect.o_file = "c:\a5\a_sports\result.dbf"
intersect.m_key = "CUST_ID"
intersect.t_key = "CUST_ID"
intersect.m_filter = ""
intersect.t_filter = ""
intersect.delete_o_dd = .T.
intersect.m_count = 6
intersect.m_field1 = "@INV_HEAD->INV_NO"
intersect.m_field2 = "CUSTOMER->CUST_ID"
intersect.m_field3 = "CUSTOMER->FIRST_NAME"
intersect.m_field4 = "CUSTOMER->LAST_NAME"
intersect.m_field5 = "@INV_HEAD->INV_TOTAL"
intersect.m_field6 = "CUSTOMER->HOME_PHONE"
tbl.intersect()
tbl.close()

See Also