# How do I sum the values of a column of a table component?

**URL:** <https://forum.inductiveautomation.com/t/how-do-i-sum-the-values-of-a-column-of-a-table-component/33837>\
**Category:** Ignition\
**Created:** [April 10, 2020, 1:37am UTC](https://forum.inductiveautomation.com/t/how-do-i-sum-the-values-of-a-column-of-a-table-component/33837 "2020-04-10T01:37:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [April 10, 2020, 1:37am UTC](https://forum.inductiveautomation.com/t/how-do-i-sum-the-values-of-a-column-of-a-table-component/33837/1 "2020-04-10T01:37:59Z")

</div>

Good night, my name is Felipe and I’m new to Ignition. I received a mission to add the hfiNumber values ​​of each process machine (eg cupper, bodymaker, decorator) to the ignition screen next to each machine. I intend to place a numeric label next to each machine on the client’s screen informing hfiNumber. I made this little application that writes the values ​​in a table named **hfi** from a MySQL database. The script in the **Submit** button is:

```auto
timeStamp = event.source.parent.getComponent('Label').text
line= event.source.parent.getComponent('Dropdown 1').selectedStringValue
machine = event.source.parent.getComponent('Dropdown').selectedStringValue
hfis=event.source.parent.getComponent('Spinner').intValue
description = event.source.parent.getComponent('Text Area').text

query = "INSERT INTO `ign_historical`.`hfi` (timeStamp, Line, Machine, hfiNumber, Description) VALUES (?,?,?,?,?)"

args = [timeStamp, line, machine, hfis, description]

system.db.runPrepUpdate(query,args)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6d1f1652d77726d64c01241d482b9a525742d7e7.png)

os valores do componente tabela vem de uma consulta SQL

```auto
SELECT * FROM hfi

```

However, as the values ​​filled in by the factory’s quality department staff (Line, Machine, hfiNumber and description) will be fed throughout the day, I don’t know how I add the hfi number values ​​of a machine during an interval shift, for example: the **Cupper** machine from **line 22** , from 7:00 am to 7:00 pm, on April 4, hfiNumber is equal to 4, the **Cupper machine** from **line 23** hfiNumber is equal to 2 (as shown in the example in the image). I do not know how I add these values ​​for a given machine during a certain time interval and the values ​​will be filled in randomly by the quality department

I tried to do this using the lookup script function, but it only returns the value of the row above the specified column, and I need the sum within a time interval, since the process is divided by shift.

the other question is also that I added edit and delete buttons, in case I want to edit a line or delete a line directly from the database. but I have no idea how to edit or delete a selected line.

In this small project I tried to use inserting data directly into the database. but if anyone has a new and more practical idea of ​​how the people in the quality department would insert these values ​​into the ignition and how I can get the data from hfiNumber will be very welcome. As I’m new to Ignition, I still have a lot to learn

thank you very much!!!

---

<div class="post-metadata">

**Author:** ![MaGottschalk](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@MaGottschalk](https://forum.inductiveautomation.com/u/MaGottschalk)\
**Post date:** [April 10, 2020, 7:07am UTC](https://forum.inductiveautomation.com/t/how-do-i-sum-the-values-of-a-column-of-a-table-component/33837/2 "2020-04-10T07:07:39Z")

</div>

Hello Felipe,

summing up the hfiNumber for a specific machine and a specific date could be done in SQL. As I’m using MSSQL, I’m not 100% sure about the correct syntax for MySQL.

```auto
SELECT 
    SUM(hfiNumber) as hfi
    , date(timeStamp) as dt
FROM hfi
  
where
	machine like 'Cupper'
	and HOUR(dt)>=7 and HOUR(dt)<19
group by date(timeStamp)
order by dt

```

This should give you the sum of hfiNumbers for the **Cupper** machine for the 7am to 7pm shift for each day.

In order to edit or delete a line you just need to read the selectedRow property of your table, get the values (see [http://forum.inductiveautomation.com/t/how-to-extract-the-value-of-the-selected-row/8817](http://forum.inductiveautomation.com/t/how-to-extract-the-value-of-the-selected-row/8817)) and then run the wanted SQL update or delete command.

---

<div class="post-metadata">

**Author:** ![Belen\_Aveldan](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@Belen\_Aveldan](https://forum.inductiveautomation.com/u/Belen_Aveldan)\
**Post date:** [March 14, 2022, 6:51pm UTC](https://forum.inductiveautomation.com/t/how-do-i-sum-the-values-of-a-column-of-a-table-component/33837/3 "2022-03-14T18:51:59Z")

</div>

Hola !!!  
Estoy intentando realizar la suma de una columna de mi base de datos, pero al hacerlo en un script de Ignition me marca el siguiente error:

Caused by Exception: Error executing system.db.runPrepUpdate(SELECT SUM(Flujo) AS Flujo FROM [dbo].[Consumo\_L] WHERE [Id\_consumo] = ?, [8], SUMIN\_AGUA, , false, false)  
caused by SQLServerException: Se ha generado un conjunto de resultados para actualización.

Y esta la consulta que estoy utilizando:  
query = “SELECT SUM(Flujo) AS Flujo FROM [dbo].[Consumo\_L] WHERE [Id\_consumo] = ?”  
args = [Id\_consumo]  
system.db.runPrepUpdate(query,args)

Espero me puedan ayudar a encontrar mi error.
