/
Addressing Columns Using Their Number

Addressing Columns Using Their Number

You can access columns using their numbers with $ followed by the column number.

This example

SELECT [f], [c]
FROM [dms]:[sysFolder] [f] JOIN [dms]:[sysParent2Child] JOIN [dms]:[customer] [r]

can therefore be reformulated to

SELECT $1, $3
FROM [dms]:[sysFolder] [f] JOIN [dms]:[sysParent2Child] JOIN [dms]:[customer] [r]
If there is a more complex type in the specified target column, then you can access its elements directly.
SELECT $1.[sysId]
FROM [dms]:[customer]

In the same way, you can also access the WHERE clause from the FROM clause.

SELECT $3
FROM [dms]:[sysFolder] [f] JOIN [dms]:[sysParent2Child] JOIN [dms]:[customer] [r]
WHERE $1.[sysid] = id'ABCDEF12345678901234567890123456'
This notation can also be used in the ORDER BY clause.
…ORDER BY $ 1

This notation is particularly suitable for dynamically combined queries. Imagine a script that receives any transferred eSQL query, in which it is only stipulated that it leads to a result table with a column and that objects are selected in the first column. Now you would like to build a filter around this query, e.g., limiting the search to a particular folder.

SELECT $3
FROM [dms]:[sysFolder] [f]
 JOIN [dms]:[sysParent2Child] [r],
 (<given query>) AS [x]
WHERE $3.[sysid] = [r].[sysid2]

The script is independent of the name of the given query's column. Without the $ notation, you need to request a particular name of the column from the caller.

Related content

SELECT Clause
SELECT Clause
More like this
Overview of the Structure of eSQL Statements
Overview of the Structure of eSQL Statements
More like this
ORDER BY Clause
ORDER BY Clause
More like this
UNION and EXCEPT
UNION and EXCEPT
More like this
References
References
More like this