Understanding Meta-SQL

This section discusses how to use Meta-SQL and its three types of elements.

Meta-SQL expands to platform-specific SQL substrings, causes another function to be called, or substitutes a value. Meta-SQL constructs are used in functions that pass SQL strings, such as the following:

  • SQLExec.

  • Scroll buffer functions (ScrollSelect and its relatives).

  • Application Designer dynamic views and SQL views.

  • Some Rowset class methods (Select, SelectNew, Fill, and so on.).

  • The SQL class.

  • Application Engine programs.

  • Some Record class methods (Insert, Update, and so on.).

  • COBOL functions.

There are three types of meta-SQL elements:

  • Constructs

    Constructs are a direct substitution of a value, and help to build or modify a SQL statement.

    Examples include %Bind, %InsertSelect, and %List.

  • Functions

    Functions perform actions or cause another function to be called.

    Examples include %ClearCursor, %Execute, and %ExecuteEdits.

  • Meta-SQL variables

    Meta-SQL variables enable substitution of text within SQL statements.

    Examples include %AsOfDate, %Comma, and %JobInstance.

Parameter markers or bind variables are most commonly used in predicates, however some database platforms allow them in the SELECT list. However, since this is not supported across all platforms, you should not code your SQL to use bind variables in a SELECT list.

In addition, do not have bind variables as the operands of the same operator. This is not supported on all platforms. DB2/400 and DB2/OS390 cannot handle this type of operation.