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. The create form does not include the query — set it on the tag's Configuration tab once the tag exists.
Protocol Fields
SQL Query
The SQL query that Koios executes against the database on each scan to read this tag's value.
- 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.
Query Restrictions
Only read queries are accepted. Koios rejects a query containing any of these keywords:
DELETE · CREATE · ALTER · DEFAULT · DROP · DATABASE · SET · TRUNCATE TABLE · UPDATE
A rejected query puts the tag into a configuration error — "Query contains a disallowed keyword" — and it never reads.
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
