# How to define runPrepUpdate with variable for column name?

**URL:** <https://forum.inductiveautomation.com/t/how-to-define-runprepupdate-with-variable-for-column-name/8449>\
**Category:** Ignition\
**Created:** [May 14, 2014, 11:42pm UTC](https://forum.inductiveautomation.com/t/how-to-define-runprepupdate-with-variable-for-column-name/8449 "2014-05-14T23:42:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shreyaslimaye](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@shreyaslimaye](https://forum.inductiveautomation.com/u/shreyaslimaye)\
**Post date:** [May 14, 2014, 11:42pm UTC](https://forum.inductiveautomation.com/t/how-to-define-runprepupdate-with-variable-for-column-name/8449/1 "2014-05-14T23:42:46Z")

</div>

Hello,

I am trying to write a system.db.runPrepUpdate statement where I want to use a variable for the name of the column that gets updated as a result of this command.

For example, the following statement works and updates the StepNumber column correctly in MySQL table.

system.db.runPrepUpdate(""“UPDATE test.HVOverlay SET StepNumber=? WHERE Timestamp = ?”"",  
[str(row[1]),str(row[0])],“MySQL”)

However, the column name could be different everytime. So, I need to use a variable instead of a fixed column name. I have been trying something like this  
colname = str(columns[i])  
system.db.runPrepUpdate(""“UPDATE test.HVOverlay SET %s=? WHERE Timestamp = ?”%(colname)"",  
[str(row[1]),str(row[0])],“MySQL”)

But I am getting a syntax error. How can I define the system.db.runPrepUpdate statement when I am using a variable for the column name?

Thanks,

Shreyas

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 15, 2014, 1:11am UTC](https://forum.inductiveautomation.com/t/how-to-define-runprepupdate-with-variable-for-column-name/8449/2 "2014-05-15T01:11:26Z")

</div>

Hi Shreyas,

Try this:

```auto
colname = str(columns[i])
system.db.runPrepUpdate("""UPDATE test.HVOverlay SET %s=? WHERE Timestamp = ?"""% (colname), [str(row[1]),str(row[0])],"MySQL")
```

---

<div class="post-metadata">

**Author:** ![shreyaslimaye](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@shreyaslimaye](https://forum.inductiveautomation.com/u/shreyaslimaye)\
**Post date:** [May 16, 2014, 12:18am UTC](https://forum.inductiveautomation.com/t/how-to-define-runprepupdate-with-variable-for-column-name/8449/3 "2014-05-16T00:18:10Z")

</div>

Thank you Nick! It worked! Nice to hear from you!

Shreyas
