Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new window

For information on migrating to InterSystems IRISOpens in a new window, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions pageOpens in a new window (login required).

<CSP:SQLQUERY>

Run a dynamic SQL query

Synopsis

<CSP:SQLQUERY>...</CSP:SQLQUERY>

Attributes

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.

Description

The <CSP:SQLQUERY> tag creates a %ResultSetOpens in a new window 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 %ResultSetOpens in a new window object. The %ResultSetOpens in a new window 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:SQLQUERY>
<ul>
<csp:WHILE CONDITION="query.Next()">
    <li>#(query.Get("Name"))#
</csp:WHILE>
</ul>
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.

<CSP:SQLQUERY DATASOURCE>...</CSP:SQLQUERY>
FeedbackOpens in a new window