# Insert value in power table at selected row in particular column

**URL:** <https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623>\
**Category:** Ignition\
**Created:** [January 16, 2023, 11:48am UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623 "2023-01-16T11:48:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aman\_sharma](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@aman\_sharma](https://forum.inductiveautomation.com/u/aman_sharma)\
**Post date:** [January 16, 2023, 11:48am UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623/1 "2023-01-16T11:48:40Z")

</div>

i have a power table and i want to insert a value at selected row at particular column.  
i created one named query :  
insert into [test]  
([complete\_date])  
values (GETDATE())  
i want to insert this current date in particular one column at selected row.  
i tried this script:  
sel\_row = event.source.parent.getComponent('Power Table').selectedRow  
id = event.source.parent.getComponent('Power Table').data.getValueAt(sel\_row, "complete\_date")  
system.db.runNamedQuery("complete task", {"complete\_date":id})  
event.source.parent.getComponent('Power Table').data = system.db.runNamedQuery("All\_task\_Query")

but values are updated in new row not at selected row.

---

<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:** [January 16, 2023, 12:44pm UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623/2 "2023-01-16T12:44:29Z")

</div>

You're using an `INSERT` statement. You need to use an `UPDATE`.

Also, it looks like you're trying to update the value of the row id? That's a bad idea. You should use an id in the row which is unique to that row and never changes.

```plaintext
UPDATE [test]
SET [complete_date] = GETDATE()
WHERE id = :id

```

---

<div class="post-metadata">

**Author:** ![aman\_sharma](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@aman\_sharma](https://forum.inductiveautomation.com/u/aman_sharma)\
**Post date:** [January 16, 2023, 12:59pm UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623/3 "2023-01-16T12:59:39Z")

</div>

i tried this but value got update in every row, i want to update in particular selected row.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/925d7de7a6d59b2021cec9e2496d87b99bbfcbef.png)

---

<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:** [January 16, 2023, 1:14pm UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623/4 "2023-01-16T13:14:43Z")

</div>

> [@lrose](#):
>
> You should use an id in the row which is unique to that row and never changes

You need to use an ID in your query which is unique to the row you want to update. You will have issues otherwise. The UPDATE will update all rows which match the where clause.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 16, 2023, 1:39pm UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623/5 "2023-01-16T13:39:17Z")

</div>

Does your database table have a [primary key](https://www.w3schools.com/sql/sql_primarykey.ASP)?

---

<div class="post-metadata">

**Author:** ![aman\_sharma](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@aman\_sharma](https://forum.inductiveautomation.com/u/aman_sharma)\
**Post date:** [January 16, 2023, 5:37pm UTC](https://forum.inductiveautomation.com/t/insert-value-in-power-table-at-selected-row-in-particular-column/68623/6 "2023-01-16T17:37:50Z")

</div>

thankyou, now its working
