Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


Run a dynamic SQL query




General Attributes

Attribute Description Value
DATASOURCE This specifies the name of an external data source to be used for this query. A string.
MODE Runtime mode of the query. “LOGICAL”, “ODBC”, “DISPLAY”, or “SYSTEM”.
NAME Name of local variable used to refer to the %ResultSet object created for this query. A string.
P1 Value of the first query parameter. A string.
P2 Value of the second query parameter. A string.
P3 Value of the third query parameter. A string.
P4 Value of the fourth query parameter. A string.
PASSWORD Optional password for the external data source. A string.
USERNAME Optional username for the external data source. A string.


The <CSP:SQLQUERY> tag creates a %ResultSet object based on a dynamic query defined by an SQL statement. The query may contain parameters (values substituted at runtime) within its WHERE clause. These parameters are specified using the ? character. The <CSP:SQLQUERY> tag defines a server-side variable, whose name is specified by the tag's name attribute, that refers to a %ResultSet object. The %ResultSet object is automatically prepared and executed (by calling its Execute method using the parameter values given by the various Pn attributes of the tag) and is ready for use within the page.

This tag is identical to the <SCRIPT LANGUAGE=SQL> tag except that it may be used to redirect the query to an external database using the Caché SQL Gateway.

The following example creates an unordered list by running a query:

<csp:SQLQUERY NAME='query' P1='A'>
SELECT ID,Name FROM IscPerson WHERE Name %STARTSWITH ? Order By Name
<csp:WHILE CONDITION="query.Next()">
Copy code to clipboard

Specifying an External Database

When the optional DATASOURCE attribute is specified, it redirects the query to an external database using the Caché Relational Gateway.