# SQL query working in Named Queries, not as a binding

**URL:** <https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217>\
**Category:** Ignition Early Access\
**Tags:** namedqueries\
**Created:** [August 7, 2019, 5:35am UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217 "2019-08-07T05:35:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai.brudevoll86](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@kai.brudevoll86](https://forum.inductiveautomation.com/u/kai.brudevoll86)\
**Post date:** [August 7, 2019, 5:35am UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217/1 "2019-08-07T05:35:22Z")

</div>

Dear Sirs

I’m trying to read all data from a table. I want to be able to select the table from a different component, by changing a parameter

I have made the following query:  
SELECT {analyse}.\*  
FROM {analyse}

This works in the testing tab when I execute the query, with the _analyse_ parameter _SAMPLES_. When using the Named query in a view I have to use “SAMPLES” with quotes to work.  
but when try to use a binding to a params property I cant find a way to make it work. I would assume this should work: “{view.params.analyse}”

searching earlier topics I found that the MySQL db should have ANSI\_QUOTES activated, but I don’t have admin access to the database

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [August 7, 2019, 7:35pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217/2 "2019-08-07T19:35:13Z")

</div>

IIRC, that binding text box expects an expression. Using `“{view.params.analyse}”` make the expression use the literal value between the quotes. You’d need to escape the quotes and use concat() or + between the quotes and the property reference to get what you want. Check out [https://docs.inductiveautomation.com/display/DOC80/Expression+Overview+and+Syntax](https://docs.inductiveautomation.com/display/DOC80/Expression+Overview+and+Syntax) to see more about escaping and strings.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 7, 2019, 8:03pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217/3 "2019-08-07T20:03:43Z")

</div>

Well, concat() wouldn’t be applicable in this case–the substitution is in the SQL structure, not a value.

---

<div class="post-metadata">

**Author:** ![kai.brudevoll86](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@kai.brudevoll86](https://forum.inductiveautomation.com/u/kai.brudevoll86)\
**Post date:** [August 8, 2019, 6:28am UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217/4 "2019-08-08T06:28:56Z")

</div>

Thanks! I bookmarked that page.

I managed to make the proper string, but pturmel is also correct that it does not help ☹

I’m not sure if I understand why it does not work, seems like the “value” behaves differently if you directly adds a value compared to adding an expression that returns the same value.

what I tested this morning:

concat(concat(""", {view.params.analyse}), “”") this returns “samples” with quotes, This does not work  
writing “samples” with quotes manually still works

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 8, 2019, 12:06pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-named-queries-not-as-a-binding/27217/5 "2019-08-08T12:06:25Z")

</div>

> [@kai.brudevoll86](#):
>
> I’m not sure if I understand why it does not work, seems like the “value” behaves differently if you directly adds a value compared to adding an expression that returns the same value.

The structure of a SQL query must be complete and static at the point it is submitted to the JDBC driver by Ignition. Structure includes schema, table, and column names. The DB parses (not executes) the structure to create an "execution plan" that identifies the tables and indices involved. Curly brace substitutions are pure string substitutions that happen before the SQL is passed to JDBC. So your original code should have worked, if ANSI quotes really is enabled. Try using reverse-single-quotes instead of the double quotes. That's MySQL's proprietary identifier quoting character.

By contrast, `?` and `:param` substitutions (for prep queries and named queries, respectively) take the place of data values in the SQL. And only data values. These substitutions happen during query execution, and use the DB's binary protocols to include data type information, so no value quoting is appropriate.
