How can I query historical data based on the value of specific tags

How would I use system.tag.queryTagHistory and find a interval of data based on run number and status. ex. Run Number 9999 and status is running

The tag historian doesn't have any capability to search history by value(s).

Use the SQL Bridge module to record related variables together in one row in a dedicated table, add indices so those columns can be efficiently searched, and use ordinary SQL to perform the searches.

(You can script the equivalent of transaction groups if you do not want to buy the SQL Bridge module. Just more work on your part.)

1 Like

You can read about the Historian tables and data structure here.

https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference

That can help, but the resulting SQL will be horribly inefficient, unless adding indices throughout the data partitions (ewwww, crush your DB).

Sorry, I wasn't promoting the Historian for this application. I meant to say that if one studies the table structure one can see why they're useless for this task (and many others). I didn't make it clear.

1 Like

The historian data is strictly for trending display and if I want to query that data I should create my own data?

No, If you specifically want to trend data by value, then you will need to store the data by a method outside of the tag historian.

If you want to trend data by date range then the Historian is designed for that.

2 Likes

See my thoughts: Durations for certain tag value - #2 by Transistor and Script about calculate the cumulative downtime - #7 by Transistor.

I suppose I should include, you could spend a lot of time writing complex queries and indexing tables to make them efficient, but the provided system.tag.queryTagHistory() does not allow for querying the data by any means other than date and time.

1 Like

You could track transitions in run number and status to find date ranges for your tag history queries. Everything everyone told you about query tag history is correct.

I wouldn't use historical logging to track these transitions. I would use transactions.

2 Likes

Yes. Either by SQL Bridge transaction group or by script.