# Named Query Parameters not Working via Variable Assignment

**URL:** <https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699>\
**Category:** Ignition\
**Tags:** database, ignition81, perspective\
**Created:** [February 14, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699 "2024-02-14T16:43:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam.haney](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@adam.haney](https://forum.inductiveautomation.com/u/adam.haney)\
**Post date:** [February 14, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699/1 "2024-02-14T16:43:39Z")

</div>

Hey all,  
I'm having an issue executing a Named Query with parameters of type QueryString that get their value from a variable.

Database: MySql

I have the following code for running a Named Query:

```auto
table_name = query_params[0]
column_name = query_params[1]
			
system.perspective.print(table_name)
system.perspective.print(column_name)
			
# Convert duration of query into Days, as this is used in Named Query
duration_in_days = Cpv_Utilities.minutes_to_days(self.custom["chart-data"]["duration-minutes"])
			
# Parameters for Named Query
params = {"tableName":table_name, "columnName":column_name, "duration":duration_in_days} 			
data = system.db.runNamedQuery("CpvDashboard/ManualChartDataDaily", params)
			

```

The Named Query's parameter types for `tableName` and `columnName` are `QueryString` and the Data Type assigned to them (in the Named Query editor) is `String`.

I have verified, via the print statements, that I have the correct string values for script variables `table_name` and `column_name`.

If I use string literals for the values of keys `tableName` and `columnName` in the `params`, the Named Query works. But when I try to assign those keys their value via variable assignment, it fails.

I would appreciate any feedback on this. Thank you.

ETA:

```auto
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"report_p4" WHERE t_stamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 90 DAY) * 100' at line 5

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)

at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:972)

at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)

at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)

at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRPreparedStatement.executeQuery(SRConnectionWrapper.java:973)

at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper.runPrepQuery(SRConnectionWrapper.java:167)

at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.runPrepQuery(NamedQueryExecutor.java:490)

at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:399)

... 32 common frames omitted

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 14, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699/2 "2024-02-14T16:46:36Z")

</div>

What is the resulting stacktrace/exception/error?

---

<div class="post-metadata">

**Author:** ![adam.haney](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@adam.haney](https://forum.inductiveautomation.com/u/adam.haney)\
**Post date:** [February 14, 2024, 4:50pm UTC](https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699/3 "2024-02-14T16:50:39Z")

</div>

@cmallonee

Sorry about that. I posted the exception. I see that it is triggering because the SQL sees a `"report_p4"` with quotes inside its query, but I'm too dumb to know how to remove those quotes from entering the query.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 14, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699/4 "2024-02-14T16:56:31Z")

</div>

1. Check the Named Query and make sure you're not wrapping the incoming param in quotes.
2. Make sure that the `query_params` iterable you're dealing with is not storing the values as strings-in-strings, like this: `'"report_p4"'`.

---

<div class="post-metadata">

**Author:** ![adam.haney](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@adam.haney](https://forum.inductiveautomation.com/u/adam.haney)\
**Post date:** [February 14, 2024, 5:02pm UTC](https://forum.inductiveautomation.com/t/named-query-parameters-not-working-via-variable-assignment/85699/5 "2024-02-14T17:02:43Z")

</div>

Dude, you're my Siddhartha. Thank you very much!

The `query_params` iterable is the array returned from a `system.tag.readBlocking` on a tag whose value is an Array of Strings. Because I eat crayons, I had manually entered the value for each index wrapped in quotes. Removing the quotes from the elements of the tag's value fixed this.
