# Tag historian and SQL database

**URL:** <https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232>\
**Category:** Ignition\
**Created:** [March 17, 2023, 2:39pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232 "2023-03-17T14:39:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [March 17, 2023, 2:39pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/1 "2023-03-17T14:39:26Z")

</div>

I _think_ I want to use the tag historian to get row from a database so I can make a histogram...

1st question: Am I overthinking this? (is there an easier way to do this?)

2nd question: I definitely **don't** want to modify the database. Is the tag historian capable of that? If so, how do I prevent that from happening?

Thanks!

---

<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:** [March 17, 2023, 2:59pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/2 "2023-03-17T14:59:16Z")

</div>

> [@hw79](#):
>
> I _think_ I want to use the tag historian to get row from a database so I can make a histogram...

Why do you _think_ that?

> [@hw79](#):
>
> I definitely **don't** want to modify the database. Is the tag historian capable of that? If so, how do I prevent that from happening?

That depends on what you mean by modify.

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [March 17, 2023, 3:08pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/3 "2023-03-17T15:08:52Z")

</div>

> [@lrose](#):
>
> Why do you _think_ that?

To be honest, I'm not sure. I'm really new to Ignition. Our company adopted it a while back, but I had been doing statistics in PowerBI and was encouraged to port my dashboards over to Ignition.

> [@lrose](#):
>
> That depends on what you mean by modify.

Modify as in, I don't want to change any data in the SQL database, I just want to look at it and use it in a chart.

---

<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:** [March 17, 2023, 3:10pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/4 "2023-03-17T15:10:44Z")

</div>

How is the data getting into the database? Is it being stored by the Tag Historian or is there another process like Transaction groups, scripting, or some third party software that is collecting the data?

Also, is this in Vision or Perspective?

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [March 17, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/5 "2023-03-17T15:19:56Z")

</div>

> [@lrose](#):
>
> How is the data getting into the database?

Short answer: Our software.

The data is from one of our processes. So it will have information for each pieces like date and time manufactured, cycle time, target weight, actual weight, serial number, etc.

> [@lrose](#):
>
> Also, is this in Vision or Perspective?

Perspective

Thanks!

---

<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:** [March 17, 2023, 3:23pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/6 "2023-03-17T15:23:47Z")

</div>

Then the answer is that you will want to use a query to pull the data. Some combination of NamedQueries, Bindings, and Scripting. There are of course ways to build the query in script, but NamedQueries would be considered best practice in most cases.

Checkout the following:

[https://docs.inductiveautomation.com/display/DOC81/Named+Queries](https://docs.inductiveautomation.com/display/DOC81/Named+Queries)  
[https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery)  
[https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepQuery)  
[https://docs.inductiveautomation.com/display/DOC81/system.db.runScalarPrepQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runScalarPrepQuery)

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [March 17, 2023, 3:25pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/7 "2023-03-17T15:25:33Z")

</div>

So basically build a query like I did in PowerBI and use it as a data source for a chart?

Thanks again!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 17, 2023, 6:08pm UTC](https://forum.inductiveautomation.com/t/tag-historian-and-sql-database/71232/8 "2023-03-17T18:08:26Z")

</div>

You might find this of some use, as well.

> [@Statistics Extensions for Ignition](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100):
>
> After discussions elsewhere with @Brian on the forum, I’ve ported the statsutils library from [http://boltons.readthedocs.io](http://boltons.readthedocs.io) some changes from the originaL Removed the format\_histogram functions, as they were using unsupported string formatting. Maybe when Ignitions’s Jython gets upgraded, I can look at it again. Renamed remaining histogram function to histogram. Brevity is good. Added ‘raw’ flag to histogram function to give a one-dimensional list with repeat histogram values, instead…
