DBEXECUTEFIXED

DBEXECUTEFIXED is an alternative to DBEXECUTE that supports parameters. Unlike DBEXECUTE, it can be used in both cloud and on-premises environments, and in custom or extended applications.

The SQL statement is treated as fixed text and, therefore, cannot directly reference variables.

If the statement is in an unprotected cell, you can update the value that it returns but, unlike with DBEXECUTE, you cannot add new rows.

Syntax

The DBEXECUTEFIXED formula has these parameters.

  1. Alias: This specifies the relational data connection that is defined in d/EPM Administration.
  2. Select statement: This is used to retrieve data from the database. It is a standard SQL SELECT command. To enable the database to be updated, the query must include the primary key. The SQL SELECT can return multiple values from a row but DBEXECUTEFIXED ignores all but the first. So, to return, and write back, a value that is not the primary key, ensure that the primary key is not the first value requested by the statement. For writeback, the cell containing the query must be unprotected.
  3. Parameter values. Parameters are referenced with the syntax @P[n].
=DBEXECUTEFIXED("alias", "select_statement", {, "parameter"})

Example

In this example, the formula returns the item name where the ID has the value currently held in the rv_configs report variable. items.ID is the primary key.

=DBEXECUTEFIXED("configdb", "SELECT items.name,items.ID FROM items WHERE Id=@p1",ReportVariables.rv_configs.Text)

items.id is the primary key. If the formula is in an unprotected cell and returns a value, you can update the value: in this example, the item name.

Note: Because the entire SQL statement is treated as text, there is no requirement to concatenate the string values with the & character, as is necessary in these DBEXECUTE formulas:
=DBEXECUTE("configdb", "SELECT items.name,items.ID FROM items WHERE Id="&ReportVariables.rv_configs.Text)
=DBEXECUTE("configdb", "SELECT items.ID,items.name FROM items WHERE name='"&ReportVariables.rv_name.Text&"'")

The syntax of the concatenation differs because, in the first example, the referenced value is numeric and in the second it is text.