Tag Usage in Report SQL Queries
Tag Usage in Report SQL Queries
Tags are used for dynamic data integration, filtering, and personalizing the result set in Report SQL queries. Your system interprets these tags in a special format alongside standard SQL syntax.
Basic Syntax and Usage
| Syntax | Description |
| Tag(TagName) | Used to display the tag itself as a column in the query result. |
| Tag(TagName).VALUE | Required to use the tag’s instantaneous value for filtering or comparison within the query. |
| Tag_1 (or TagName) | If column names in the database are not Tags, they can be written directly. |
Tag Usage by Data Type
1. BOOL Types
Boolean tags are automatically translated to ‘0’ (False) or ‘1’ (True) in the query, instead of true/false.
- Example: The query SELECT Tag(BooleanTag_0) FROM Table1 displays the value ‘0’ in the compiled result field (if the value is False).
2. Date/Time Types
Date/time tags appear in a fixed format within the SQL query.
- Note: This format may differ from your computer’s local date/time settings.
- Example: The query SELECT Tag(Now) FROM Table1 displays a value in the format ‘2025-10-15 10:03:06’ in the compiled result field.
3. REAL Numbers
When comparing Real number values, a dot (.) must be used as the decimal separator to comply with SQL standards.
- Note: The system automatically converts real numbers to the dot format, even if your local settings use commas.
- Example: SELECT * FROM Table1 WHERE Tag(Tag_1).VALUE > 1.0
4. String Types
String (Text) tag values can be used in two ways:
- With Quotes: Used for filtering values.
- Example: LastValue = ‘Tag(UserName)’. In the compiled query, the value is written inside quotes.
- Without Quotes: Used when the tag represents a tag name or a structural part of the query.
- Example: LastValue = Tag(UserName).
Advanced Usage Scenarios
1. Printing Value as a Column (.VALUE Usage)
- Use .VALUE to display the instantaneous value of a tag as a column in the query result, rather than the tag’s name.
- Example: The query SELECT Tag(UserName).Value, Tag_2 FROM Table1 writes the value of the UserName tag (e.g., ‘1000’) to the result table instead of the tag name itself.
2. Renaming Columns (AS Keyword)
- Use the AS keyword to assign an alias to a tag or column that will be displayed in the result set.
- Example: Using ‘Tag_1 AS MyTag’ ensures that the Tag_1 column is renamed to MyTag in the output.
3. Dynamic SQL Querying
- The system allows for fully dynamic SQL querying using the content of a String type tag. By changing the string content of the tag, you can dynamically alter the entire query or a part of it.
- Example: In the structure WHERE LastValue > Tag(UserName), if the UserName tag contains the text ‘0’, the query logic becomes LastValue > ‘0’.
4. Writing Last Row to SCADA Tags
- The SET LAST ROW VALUES command is used to write the data obtained from the last row of the report query back to SCADA tags.
- This allows report results to trigger or update other processes in the system.
- Syntax: SET LAST ROW VALUES:,,Tag_1,Tag_2
