Parameterized SQL Queries

Parameterized SQL queries allow you to place parameters in an SQL query instead of a constant value. A parameter takes a value only when the query is executed, which allows the query to be reused with different values and for different purposes. Parameterized SQL statements are available in some analysis clients, and are also available through the Historian SDK.

For example, you could create the following conditional SQL query, which contains a parameter for the collector name:

SELECT* FROM ihtags WHERE collectorname=? ORDER BY tagname

If your analysis client were to pass the parameter iFIX_Albany along with the query, it would look like this when executed in Historian:

SELECT* FROM ihtags WHERE collectorname='iFIX_Albany' ORDER BY tagname

The benefit of parameterized SQL queries is that you can prepare them ahead of time and reuse them for similar applications without having to create distinct SQL queries for each case. The previous example, for instance, could be used in any context where you want to get tags from a collector. Parameterized queries can also be used with dynamic data, where you don't know what the values will be until the statement is executed.

If your analysis client supports parameterized queries, it will automatically pass the parameter data along with a named query for Historian to process. In the case of multiple parameters, the analysis client will read the named query, and order the parameters to match.

Consult your analysis client's documentation for support and usage of parameterized SQL queries.

Note: You cannot use parameters to substitute table names or columns in a query.