# Using Named Queries to Pull SQLite Tag Historian Data to Find Delta Time

**URL:** <https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [April 13, 2022, 7:09pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434 "2022-04-13T19:09:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isaac\_Hodgkins](https://avatars.discourse-cdn.com/v4/letter/i/59ef9b/32.png) [@Isaac\_Hodgkins](https://forum.inductiveautomation.com/u/Isaac_Hodgkins)\
**Post date:** [April 13, 2022, 7:09pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434/1 "2022-04-13T19:09:59Z")

</div>

I have a tag that returns a string value of “Running”, “Paused” or “Stopped”. I’d like to take the delta time between each status change and then sum it to get the total run, pause and stop time.

In some versions of SQL there is a lag/lead function to accomplish this but it doesn’t seem to be present in the Ignition version.

Any ideas on how I can best accomplish this?

Thank you!

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/1/2136526983f84a21d881e0902c46d7aaa8858887.jpeg)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 13, 2022, 7:30pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434/2 "2022-04-13T19:30:53Z")

</div>

I would switch away from SQLite. It is not a high-volume production database. If you need free, MariaDB and PostgreSQL are both free and support lead/lag.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 13, 2022, 7:33pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434/3 "2022-04-13T19:33:39Z")

</div>

You can also use a script transform in a binding and use Python to generate the differences. Return them as a dictionary, `{"Running": 1234, "Paused": 4321, "Stopped": 1111}` for use in your display.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 13, 2022, 8:06pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434/4 "2022-04-13T20:06:13Z")

</div>

> [@Isaac\_Hodgkins](#):
>
> In some versions of SQL there is a lag/lead function to accomplish this but it doesn’t seem to be present in the Ignition version.

You're not required to use the SQLite Tag Historian. You can create a History Provider for any Database connection in Ignition.

In case it isn't obvious, SQLite isn't an "Ignition" thing, it is just a Tool that Ignition happens to use for some things (other than the initial history provider)

---

<div class="post-metadata">

**Author:** ![Isaac\_Hodgkins](https://avatars.discourse-cdn.com/v4/letter/i/59ef9b/32.png) [@Isaac\_Hodgkins](https://forum.inductiveautomation.com/u/Isaac_Hodgkins)\
**Post date:** [April 13, 2022, 8:19pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434/5 "2022-04-13T20:19:20Z")

</div>

Thanks, I just finished setting up MariaDB and it’s working now!

---

<div class="post-metadata">

**Author:** ![Isaac\_Hodgkins](https://avatars.discourse-cdn.com/v4/letter/i/59ef9b/32.png) [@Isaac\_Hodgkins](https://forum.inductiveautomation.com/u/Isaac_Hodgkins)\
**Post date:** [April 13, 2022, 8:25pm UTC](https://forum.inductiveautomation.com/t/using-named-queries-to-pull-sqlite-tag-historian-data-to-find-delta-time/58434/6 "2022-04-13T20:25:18Z")

</div>

Haha yeah I realize that now. I’m very new to this stuff and am trying to create an ignition demo for my plant as someone with a ME background. A lot of these basic concepts go right over my head. Thanks for explaining this.
