The instruction that Sage X3 makes available to make a join between two tables is
Link
.
Here we see how to create a join between the TAB1 table and the TAB2 table;
TAB1 is the table with more detail,
The link is based on the TAB2 table.
TAB1 is the table with more detail,
The link is based on the TAB2 table.
Key index is KEY0, it’s made up of 2 fields which in this case correspond to the fields FIELD1TAB2 and FIELD2TAB2 of TAB2:
Attention: the join statement must be written all on one line, or alternatively you can use the character
&
as seen here.
The keyword that defines the link between the two tables is
With
that corresponds with “ON” in an SQL statement:
To express a condition in FULL JOIN, use the
To express a condition in LEFT JOIN use the
~=
operator (tilde equal)To express a condition in LEFT JOIN use the
=
operator (equal)
Before joining you must declare / open the tables you want to use,
and it is possible to declare the same table twice, with different abbreviations.
and it is possible to declare the same table twice, with different abbreviations.
For example, the detail table is TABDETAIL and the and the table to be joined is TAB2:
this is the syntax (as already said everything goes on the same line, in brackets the optional parts):
this is the syntax (as already said everything goes on the same line, in brackets the optional parts):
CONDITION_JOIN
There must be at least one CONDITION_JOIN and maximum 11.
Up to 12 tables can be put in JOIN.
KEY_NAME is the name of a table index, so to speak those defined in the “Index” tab in the GESATB function.
As we can see, the join condition is conditioned to the use of fields that belong to at least one table index,
therefore you can not set a join on any field.
Up to 12 tables can be put in JOIN.
KEY_NAME is the name of a table index, so to speak those defined in the “Index” tab in the GESATB function.
As we can see, the join condition is conditioned to the use of fields that belong to at least one table index,
therefore you can not set a join on any field.
JOIN_NAME
In practice we give a name to the join class thus created, which can be used with a statement;
for example a FOR statment:
In practice we give a name to the join class thus created, which can be used with a statement;
for example a FOR statment:
Then any WHERE conditions and any sorting with ORDER BY must be added.
Let’s see some examples.
Inner join example
We try to recover the tax code of customers whose code starts with ‘AAA’.
We retrieve the tax code from the CRN field of the BPs table.
Not all BPs are customers, so we set up an inner join to get only records that match the BPCUSTOMER table.
We retrieve the tax code from the CRN field of the BPs table.
Not all BPs are customers, so we set up an inner join to get only records that match the BPCUSTOMER table.
If in the join condition remove the tilde
~
all BPs will be displayed, even those who are not customers.Left join example with link one-to-many
We look for all the articles with their articles-site.
An article can have multiple matches in the table of articles-site (one to many relationship).
However, we also want to display all the articles that do not have any site articles.
An article can have multiple matches in the table of articles-site (one to many relationship).
However, we also want to display all the articles that do not have any site articles.
In this way, an article without an article-site will still be displayed.
Note that in this case we used the syntax [TAB2] KEY_NAME (INDEX_VALUE):
in fact we have set the join only on the first field of the ITF0 key which is as follows:
in fact we have set the join only on the first field of the ITF0 key which is as follows:
The problem is that the link statement requires the use of a key in the join condition,
and you have to make do with the keys present or create a new one.
and you have to make do with the keys present or create a new one.
Per trovare molte alte informazioni sull’istruzione Link di Sage X3
To find more information on the Sage X3 Link statement click here.
To find more information on the Sage X3 Link statement click here.