TABLE

TABLE takes a table or a query expression and returns a table.

 

TABLE [mfd_root];

 

A handy use of this simple form of TABLE is to create a simple query that, in effect, provides a shortcut within a data source that refers to a table in a different data source.    For, example, the Edit - Join dialog provides point and click JOIN capability without any need to write SQL, but it only works on tables and queries within the same data source.   We can refer to tables and queries in subsidiary data sources by writing a short query using TABLE, such as:

 

TABLE [database]::[titles];

 

The query, in the local data source, repeats data from a table in a different data source, specifically, the [database]::[titles] table.  It is like creating a Windows shortcut in File Explorer.

 

 

TABLE CALL executes a query function that is, a CALL to a function that returns a table.

 

TABLE CALL CoordSystems();

 

TABLE CALL SystemGpgpus();

 

TABLE CALL ValueSequence(1, 10, 1);

 

Examples

Within a function:

 

FUNCTION f() TABLE AS (TABLE CALL ValueSequence(0, 10, 2)) END;

SELECT * FROM CALL f();

 

Another use of a function, with TABLE CALL:

 

FUNCTION f(@T TABLE) TABLE AS

  (SELECT Max([Population]) FROM @T) END;

TABLE CALL f([States Table]);

 

The following query works OK because we are passing a parameter @n from the EXECUTE WITH to the TABLE clauses:

 

FUNCTION f(@T TABLE) TABLE AS

  (SELECT Max([Population]) FROM @T) END;

EXECUTE WITH (@n TABLE = CALL f([States Table])) [[ TABLE @n; ]]  ;

 

This query does not work because what is inside the [[  ]] brackets is in a separate execution context that cannot see the function definition that comes before the EXECUTE WITH statement:

 

FUNCTION f(@T TABLE) TABLE AS

  (SELECT Max([Population]) FROM @T) END;

EXECUTE WITH (@n TABLE = [States Table]) [[ TABLE CALL f(@n); ]]  ;

 

If we wanted to use the function, we could define it within the [[  ]] brackets.  This works OK:

 

EXECUTE WITH (@n TABLE = [States Table])  [[

    FUNCTION f(@T TABLE) TABLE AS

      (SELECT Max([Population]) FROM @T) END;

    TABLE CALL f(@n);

]] ;

 

 

See Also

Queries

 

Command Window

 

Query Builder

 

SQL Statements

 

EXECUTE

 

GROUP BY

 

SPLIT Clause

 

TABLE

 

UNION / EXCEPT / INTERSECT

 

VALUE

 

VALUES