# SQL query working in query browser, not as a binding

**URL:** <https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291>\
**Category:** Ignition\
**Created:** [September 9, 2017, 8:51pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291 "2017-09-09T20:51:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Plantformance](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@Plantformance](https://forum.inductiveautomation.com/u/Plantformance)\
**Post date:** [September 9, 2017, 8:51pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291/1 "2017-09-09T20:51:35Z")

</div>

Hey guys

I have the following query

SELECT  
param\_code as name,  
“station\_forCanvas” as template,  
200+200\*COS(PI()_param\_angle/180.0) as x,  
200+200_SIN(PI()\*param\_angle/180.0) as y,  
50 as width,  
50 as height,  
10 as z,  
CONCAT( “{”, char(34), “station”, char(34), “:” , char(34), fullpath , char(34), “}” ) as parameters  
FROM  
tw\_data\_list\_stations  
WHERE  
id\_machine = 2  
AND  
tw\_data\_list\_stations.table = 1

It works great in Query Browser. However when used as a binding, I get the message “… not well formed”. I found it is linked to the usage of “{” character (want to build a dictionnary for template canvas).

Some ideas ?  
It is annoying as I have to use an interim table, and complete the job with python programming. The most funny part being that it works in query browser ☹

thanks !🙂

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [September 9, 2017, 10:15pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291/2 "2017-09-09T22:15:24Z")

</div>

Does it help if you use single quotes in order to be able to get rid of the `char(34)` in the `CONCAT` expression? e.g.

```sql
SELECT 
param_code as name,
'station_forCanvas' as template,
200+200*COS(PI()*param_angle/180.0) as x,
200+200*SIN(PI()*param_angle/180.0) as y,
50 as width,
50 as height,
10 as z,
CONCAT( '{"station": "', fullpath, '"}' ) as parameters
FROM
tw_data_list_stations
WHERE
id_machine = 2
AND
tw_data_list_stations.table = 1

```

Perhaps there is something getting confused in the binding usage? btw, you can get better syntax highlighting in here for code sections by surrounding them with three back-ticks (to the left of the 1 key):

```  
code here  
```

---

<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:** [September 9, 2017, 11:09pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291/3 "2017-09-09T23:09:25Z")

</div>

Standard SQL doesn’t allow double-quote characters as string delimiters at all. You must use single quotes.

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [September 10, 2017, 1:44am UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291/4 "2017-09-10T01:44:54Z")

</div>

Edit: Re-looking at this I am seeing that this is indeed using the `CONCAT` function in SQL. My brain was thinking that it was an Ignition expression function. Hopefully the adjusted form I posted will work then for ya… Thanks @pturmel.

---

<div class="post-metadata">

**Author:** ![Plantformance](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@Plantformance](https://forum.inductiveautomation.com/u/Plantformance)\
**Post date:** [September 10, 2017, 7:31am UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291/5 "2017-09-10T07:31:20Z")

</div>

Thanks guys.  
But there is something else.

Try **select “{”+“test”+"}" as mystring** in query browser =\> works 🙂

Try now to put a text in a window, and bind it to the text =\> “not well formed” 😞

I have the impression the interpreter does not go the same route, and the { are replaced at some point.  
It is very annoying (even more if you use JSON type in MySQL tables).

---

<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:** [September 10, 2017, 1:19pm UTC](https://forum.inductiveautomation.com/t/sql-query-working-in-query-browser-not-as-a-binding/15291/6 "2017-09-10T13:19:12Z")

</div>

The query browser appears to be passing the SQL straight to MySQL, which does allow double-quotes for string literals. In standard SQL, double quotes are for identifiers like table names and column names that would otherwise be mangled. Consider turning on ANSI\_QUOTES in your MySQL server to help enforce proper quoting.  
Anywhere Ignition needs to pre-parse SQL, it’ll be using standard rules.
