Database tables
TABLE
The code to insert a value for a database table is {TABLE}. It requires at least one parameter, which is the name of the column from which to pick the value. As an alternative, the argument may be an integer, which is a zero-based column index. In general it is recommended to use the name of the column and not the index.
Example:
Product:
{TABLE;Description}
Assuming the table has a column "Description", which on the current row has the value "Bananas", the following would be printed:
Product: Bananas
XTABLE v4.2
The {XTABLE} code performs a key-based lookup in a table — searching for a row where a specified column matches a given key, and returning the value from another column. Unlike {TABLE}, which reads from the current row in the active print job environment, {XTABLE} can query any named table regardless of context.
All parameters are required except fallback. If no matching row is found and no fallback is provided, an error is raised.
| Parameter | Type | Description |
|---|---|---|
tableName | string | Name of the table to query. |
keyColumn | string | Column name to search in. |
key | string | Value to search for in keyColumn. Supports dynamic text. |
valueColumn | string | Column name whose value to return. |
fallback | string | Value to use if no matching row is found. Supports dynamic text. |
Example:
Country:
{XTABLE;Countries;Code;{VARIABLE;country_code};Name}
This looks up the row in table "Countries" where column "Code" matches the value of variable country_code, and prints the corresponding "Name" column value.
With a fallback:
Country:
{XTABLE;Countries;Code;{VARIABLE;country_code};Name;Unknown}
If no matching row is found, "Unknown" is printed instead of raising an error.