Overview
The Dataset Module offers powerful configuration options for managing queries efficiently. Users can define queries with custom names, select database configurations, and input SQL statements, including Tag embedding. Mapping options enable data population from query results, and users can specify time references (UTC or Local) for Date Time fields.
In addition, the Dataset Module allows users to display query results using Datagrids in screens and dashboards, simplifying data visualization. Query results can also trigger actions in custom scripts and tags, enhancing automation capabilities for notifications and tag updates. For more advanced functionalities, users can explore Stored Procedures.
Creating Queries
To create and configure a Dataset Query, follow the steps below:
- Access Datasets / Queries.
- Click the plus icon.
Enter a Name and Description for the Query
Click Ok.
Define the DB (Database Connection), and Go To SQL Query editor to define the Query (you can navigate using the tree or double-click the SqlStatement column)
The use of spaces is not allowed in the Name. Instead, use underscores. For example My_Query.
Use Meaningful Names
By Default, the system will name the create the Dataset.Query with Query1, Query2,... We recommend giving a more meaningful name and using the description field, all in order to properly identify each query.
Enhance Query Flexibility with Real-Time Parameters
Adding real-time parameters to your queries offers flexibility and adaptability, enabling dynamic data retrieval based on changing conditions. Instead of hardcoding specific values, you can use dynamically populated placeholders at runtime.
Instead of using Queries like the following:
SELECT * FROM your_table WHERE col1 = 5
Use Queries with real-time parameters:
SELECT * FROM your_table WHERE col2 = {{tag.Test}}
In this example, {{tag.Test}} serves as a placeholder for a real-time parameter.
You can modify the Query settings after its creation. Double-click the property you wish to edit on the row corresponding to the Query you want to modify. The following table lists all possible configuration properties.
Column | Description |
---|---|
Name | The Query's name. The system will warn you if you choose an invalid name. |
DB | Defines the database where the Query will be executed. |
SqlStatement | Specify the Query using SQL syntax. You can embed Tags directly on the SQL statement, embracing the tag with curly brackets. For example, ColumnName = {tag.tagInt}. Alternatively, you can update the SQL Statement with the Script module accessing the property Dataset.Query.QueryName.SqlStatement. If you access that property from multiple tasks using this approach, be aware of potential concurrency issues. For more information, access Advanced Dataset Guide. |
Mapping | Click the three dots button (...) to select the tags you want to populate with data from specific columns the Query returns. |
MappingDateTime | Specify how the time in Database will be interpreted (UTC or Local), when mapping to DateTimeOffset .NET variables. |
Description | Query's description. |
Editing Queries
The queries are ending using the Built-In SQL Query Editor, which assists doing the hight of the SQL Syntax.
→ Learn more at the Query Editor page.
There is also the tool VisualQueryBuilder which allows to explore databases, and drag-drop tables and visually connect fields to build the Query.
The VisualQueryBuilder is started navigating to Datasets → DBs, and clicking on the Visual Query Builder button.
→ See Visual SQL Query Builder for more information on that tool.
Testing Queries
The best place to test your queries is the DataExplorer SQL Queries tool.
Any query used in the solution, or even new queries you are modifying in that environment can be executed.
The results are presented in a DataGrid object in wich you can customize the columns.
→ Learn more at Data Explorer SQL Queries.
In this section...