Creating a Microsoft SQL Tag
After creating a tag on a Microsoft SQL device, you need to provide the SQL query that Koios will execute to read this tag's value. You can configure this during creation or afterwards on the tag's Configuration tab.
Protocol Fields
SQL Query
The SQL query that Koios executes against the database on each scan to read this tag's value.
- Optional during creation, but required for the tag to collect data
- The query should return a single numeric value
- Maximum length: 1,024 characters
Query Guidelines
Return a single value. Koios reads the first column of the first row of the result set. If your query returns multiple rows or columns, only the first value is used.
Keep queries lightweight. The query runs on every scan cycle, so avoid expensive joins, full table scans, or complex aggregations that could slow down the database.
Use parameterized values where possible. If you need the most recent reading, use TOP 1 with an ORDER BY on the timestamp column rather than scanning the entire table.
Example Queries
Latest sensor reading:
Aggregated value:
Count of active alarms:
After Configuration
- Save the tag configuration
- Test the tag — clickTestto verify the query returns a valid value (see Testing a Tag)
- Enable the tag — flip the enable switch to start collecting data
