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 Historian SDK.

For example, the following query contains a parameter for the collector name:

SELECT* FROM ihtags WHERE collectorname=? ORDER BY tagname

If your analysis client passes the parameter iFIX_Albany along with the query, it looks like follows when executed in Historian:

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

The advantage of using 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. For instance, you can use the previous example in any context where you want to get tags from a collector. You can also use parameterized queries with dynamic data, where you do not 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.

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