# UPDATE Query Syntax issue

**URL:** <https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467>\
**Category:** Ignition\
**Created:** [September 15, 2015, 1:32pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467 "2015-09-15T13:32:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [September 15, 2015, 1:32pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/1 "2015-09-15T13:32:37Z")

</div>

So I started with my SQL Code within the Database Query Browser and I was able to do an update query with no issue 🙂 This is just a basic edit row SQL script so I could make sure I got the syntax correct:

`UPDATE sensor_notes
SET operator = 'admin'
WHERE operator = 'rodney'`

Then I took this code, and tried to make it dynamic so that the user would be able to edit data within the database based on text fields within the screen. This is what I got:

[code]name = event.source.parent.getComponent(‘Text Field 4’).text  
operator = event.source.parent.getComponent(‘Text Field 5’).text  
latitude = event.source.parent.getComponent(‘Text Field 2’).text  
longitude = event.source.parent.getComponent(‘Text Field 3’).text  
description = event.source.parent.getComponent(‘Text Field 1’).text  
db = “DB”  
updateQuery = “”“UPDATE sensor\_data SET name = ?, operator = ?, latitude = ?, longitude = ?, description = ? WHERE name = ?  
VALUES (?,?,?,?,?,?)”""

system.db.runPrepUpdate(updateQuery, [name, operator, latitude, longitude, description, name], db)[/code]

Unfortunately, I keep getting an error code 😠

This is the entirety of the error I keep getting:  
Traceback (most recent call last):

File “event:actionPerformed”, line 10, in

VALUES (?,?,?,?,?,?), [Sensor 2, Dave, 12.34, 2.4.68, D2, Sensor 2], DB, , false, false)

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE sensor\_data SET name = ?, operator = ?, latitude = ?, longitude = ?, description = ? WHERE name = ?

VALUES (?,?,?,?,?,?), [Sensor 2, Dave, 12.34, 2.4.68, D2, Sensor 2], DB, , false, false)

```
caused by Exception: Error executing system.db.runPrepUpdate(UPDATE sensor_data SET name = ?, operator = ?, latitude = ?, longitude = ?, description = ? WHERE name = ?

```

VALUES (?,?,?,?,?,?), [Sensor 2, Dave, 12.34, 2.4.68, D2, Sensor 2], DB, , false, false)  
caused by GatewayException: SQL error for “UPDATE sensor\_data SET name = ?, operator = ?, latitude = ?, longitude = ?, description = ? WHERE name = ?  
VALUES (?,?,?,?,?,?)”: No value specified for parameter 7  
caused by SQLException: No value specified for parameter 7

Ignition v7.7.5 (b2015071516)  
Java: Oracle Corporation 1.8.0\_51

Any ideas as to what’s going on? It says no value specified for parameter 7, but I only have 6 parameters there, right? I’m just a tad confused as to what’s going on ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

I’m currently running Version 7.7.5, so I believe that I am up to date on my software as well.

Thanks in Advance for all the help! 😃

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [September 15, 2015, 2:18pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/2 "2015-09-15T14:18:53Z")

</div>

Count the number of question marks in your updateQuery statement.

“VALUES (?,?,?,?,?,?)” is not needed.

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [September 15, 2015, 2:23pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/3 "2015-09-15T14:23:07Z")

</div>

I counted the ?s and there were 6 in the query and in the values, but…

Getting rid of the “VALUES (?,?,?,?,?,?)” Worked!! Thank you so much!

Do you know why it is that I need to use the question marks in some SQL scripts, but not in others? Thanks so much!

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [September 15, 2015, 2:56pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/4 "2015-09-15T14:56:28Z")

</div>

You are already specifying the values that you want the columns to be inside of your query:

```auto
UPDATE sensor_data SET name = ?, operator = ?, latitude = ?, longitude = ?, description = ? WHERE name = ?
```

Each question mark in the above statement gets replaced with the values in your python list [] when using a prepQuery function. This is how you can make these queries dynamic with code. If you don’t need a dynamic query then you don’t need the ?s at all.

You only have to use the VALUES() statement with an INSERT INTO query, like so:

`INSERT INTO table_name (column1, column2, column3, etc...)
VALUES(value1, value2, value3, etc...)`

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [September 15, 2015, 3:14pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/5 "2015-09-15T15:14:21Z")

</div>

Did it just happen to work out for me because the names of my columns were also the names of the variables that I had defined in my code? Just want to make sure I know what I’m doing so next time this happens, I can troubleshoot it myself and not have to pester the good people on this forum 😉

Thank you for the question mark clarification on the INSERT statements as well 🙂

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [September 15, 2015, 4:00pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/6 "2015-09-15T16:00:13Z")

</div>

[quote=“alewayhar”]I counted the ?s and there were 6 in the query and in the values, but…

Getting rid of the “VALUES (?,?,?,?,?,?)” Worked!! Thank you so much!

Do you know why it is that I need to use the question marks in some SQL scripts, but not in others? Thanks so much![/quote]

When you had VALUES (?, ?, ?, ?, ?, ?) in your updateQuery variable there were a total of 12 question marks.

The question marks are simply a placeholder for values in the system.db.runPrepUpdate function.

The VALUES clause is not used in T-SQL update statements.

Edit:

You are getting mixed up between basic T-SQL syntax and Ignition scripting. The question marks have nothing to do with the actual SQL query.

I recommend becoming very familiar with basic T-SQL statement and syntax outside of Ignition before you go much further. Solidifying these concepts should make things much clearer for you.

[T-SQL Update statement](http://www.w3schools.com/sql/sql_update.asp)

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [September 15, 2015, 8:19pm UTC](https://forum.inductiveautomation.com/t/update-query-syntax-issue/10467/7 "2015-09-15T20:19:39Z")

</div>

Thank you so much for the help! I’m glad to know you references W3. That’s where I’ve been getting a lot of my info from. Thanks again!
