Creating Query Tags
Query Tags execute a SQL Query, whose result provides the value for the Tag. Like SQL binding in Vision, SQL Query Tags can reference other tags to build dynamic queries. Query Tags cannot be written to. The value of a SQL Query tag comes from the database through a SQL query.
To create a SQL query tag
-
In Tag Bowser, right-click on Tags or a folder of your choice and select New Tag > Query Tag.
-
In the Tag Editor window, type Current Time for Name and choose DateTime for Data Type.
-
Click on SQL Query tab on the left side of Tag Editor.
-
Type in any SQL query you want.
Note: The query must return a scalar result because the data type is not a dataset. -
In the drop-down list, select the database to run the query through, for example MySQL.
-
Copy in the following query:
SELECT
CURRENT_TIMESTAMP
Query Type
In certain circumstances you may want to update the database instead of querying it for data. The query tag will accept an update query and update the target data source. The value attribute of the tag becomes the number of rows affected by the update query.
The data source refers to the default data source of the tag provider as opposed to the default data source of the project.
In the Gateway Configure Section, go to Tags > Realtime and edit the appropriate tag provider. Set the default database connection that this tag provider will use for its query tags.
-
Click OK.
You will see the value from your SQL query on the Current Time Tag.
Next ...
-
add link here