# Inserting data from a Power table into SQL database table

**URL:** <https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070>\
**Category:** Ignition\
**Created:** [January 27, 2023, 2:11am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070 "2023-01-27T02:11:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cole.sharrah](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@cole.sharrah](https://forum.inductiveautomation.com/u/cole.sharrah)\
**Post date:** [January 27, 2023, 2:11am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/1 "2023-01-27T02:11:50Z")

</div>

I have a power table on a screen that is showing tag values. The tag values are being populated from a tag history binding and a shared script. The explanation of how the table is being creating is at the end.

My goal is to take what I see in that power table and put it into a SQL table. Constantly updating the SQL table every minute and writing over the old data.

I am thinking of somehow writing the data from the table into a dataset tag and then writing what is in the dataset tag to the SQL database table.

I am open to other options.

---

<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:** [January 27, 2023, 2:20am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/2 "2023-01-27T02:20:01Z")

</div>

> [@cole.sharrah](#):
>
> My goal is to take what I see in that power table and put it into a SQL table.

But the Tag Historian already has it in SQL. You wish transfer from SQL to SQL via a Power Table? What happens when no client is open? Or two or five or ten clients?

Please share what you really need so we can provide useful advice.

---

<div class="post-metadata">

**Author:** ![cole.sharrah](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@cole.sharrah](https://forum.inductiveautomation.com/u/cole.sharrah)\
**Post date:** [January 27, 2023, 2:28am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/3 "2023-01-27T02:28:39Z")

</div>

I created another ticket for this but I this gives the explanation of how the table is created. It is not just moving data from table to table.  
Each row is related to a different site/well. It is getting the most current historical record for 28 different tags related to 45 different wells from 8 site locations.

Basically taking certain tag values from all over the project and putting them in a SQL table, updating it with realtime values every minute or so.

Secondary/Explanation: Improving the way the table is created. This table's purpose is to show Realtime values.  
This is the shared script compiling the data. Global Script:  
[Shared Script Systems Overview.txt](https://forum.inductiveautomation.com/uploads/short-url/wMkehstCx9rEYpnGdl4MfdQFCEN.txt) (30.7 KB)

This is the binding on the data property of the power table.  
[Systems Overview Data Binding.txt](https://forum.inductiveautomation.com/uploads/short-url/t9h2dXK3IlmfFgEMCziO9o8z7yQ.txt) (1.2 KB)

Here is part of the table. It has 28 columns and 45 rows. The rows will get larger in the future.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/2037864bfb113a38922c4b2e407c030f5080975b.png)

---

<div class="post-metadata">

**Author:** ![cole.sharrah](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@cole.sharrah](https://forum.inductiveautomation.com/u/cole.sharrah)\
**Post date:** [January 27, 2023, 3:01am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/4 "2023-01-27T03:01:20Z")

</div>

The window has the properties shown below.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/6700f3b2c9b369fb8a8d4d0f258bdfc7fb31cacc.png)

The binding on each of the properties is shown below.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4c59e9c5a3ec6cd257ca2ea2d07db1f6879eff1e.png)

---

<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:** [January 27, 2023, 3:04am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/5 "2023-01-27T03:04:09Z")

</div>

> [@cole.sharrah](#):
>
> This is the shared script compiling the data. Global Script:  
> [Shared Script Systems Overview.txt](https://forum.inductiveautomation.com/uploads/short-url/wMkehstCx9rEYpnGdl4MfdQFCEN.txt) (30.7 KB)
> 
> This is the binding on the data property of the power table.  
> [Systems Overview Data Binding.txt](https://forum.inductiveautomation.com/uploads/short-url/t9h2dXK3IlmfFgEMCziO9o8z7yQ.txt) (1.2 KB)

Ew!

All this to display the most recent values of tags?

Are the tags arranged in folders with identical inner tag names? (Or UDTs, which have the same effect?)

If so, a template that displays one row of tag values, using indirect binding, arranged in a template repeater, would be far more performant. With no SQL at all. (The template repeater would be set to dataset mode, and that dataset's one column would have the necessary tagpath strings.)

---

<div class="post-metadata">

**Author:** ![cole.sharrah](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@cole.sharrah](https://forum.inductiveautomation.com/u/cole.sharrah)\
**Post date:** [January 27, 2023, 3:19am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/6 "2023-01-27T03:19:40Z")

</div>

I agree it is cumbersome. It started with only 3 rows and has grown over time. I will look into making it cleaner in the future, but what I need right now is to just put all this data in SQL.

Hopefully we can forget how the table is made for now. -- Because, I have a button, that when clicked, creates an excel spreadsheet simply based on what is in the power tables cells at that time. I am hoping I can use the same mentality to just take what is currently in the Power Table and dump it into a SQL table.

Another department needs this data to be in a SQL table, in the same fashion as they see it on the screen so they can extract it for a report.

Like a runPrepUpdate funtion to take the whole table and insert it into a SQL table.

---

<div class="post-metadata">

**Author:** ![cole.sharrah](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@cole.sharrah](https://forum.inductiveautomation.com/u/cole.sharrah)\
**Post date:** [January 27, 2023, 3:26am UTC](https://forum.inductiveautomation.com/t/inserting-data-from-a-power-table-into-sql-database-table/69070/7 "2023-01-27T03:26:02Z")

</div>

Also, there are some identical inner tag names but few to many variations so it is not templated across the board.
