# Fail to write to database with property included inside the SQL query

**URL:** <https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670>\
**Category:** Ignition\
**Tags:** ignition79, database\
**Created:** [September 14, 2018, 9:12am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670 "2018-09-14T09:12:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [September 14, 2018, 9:12am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/1 "2018-09-14T09:12:59Z")

</div>

Greeting,

I face a problem while I am trying to run a SQl query which included Ignition property inside.  
If is not available to included property inside the query? or I didnt set up some setting?

My SQL Query=SELECT Item\_Name, Item\_Weight, t\_stamp FROM container WHERE Storage\_Bay = {baypopup.bayNo}

{baypopup.bayNo}=property of a template  
My database connection and satus are both valid.

error message I get is as below:

Message:

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/9aa86422ca19b9d4c2d508908ccccba353f0031f.png)  
Details:  
Exception: Error running query:  
SQLQuery(query=SELECT Item\_Name, Item\_Weight, t\_stamp FROM container WHERE Storage\_Bay = , database=DB)@5000ms  
On: baypopup.baypopup.Template Repeater.templateParams  
caused by GatewayException: 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 ‘’ at line 1  
caused by MySQLSyntaxErrorException: 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 ‘’ at line 1

Ignition v7.9.8 (b2018060714)  
Java: Oracle Corporation 1.8.0\_181

---

<div class="post-metadata">

**Author:** ![StefanGronberg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stefangronberg/32/6288_2.png) [@StefanGronberg](https://forum.inductiveautomation.com/u/StefanGronberg)\
**Post date:** [September 14, 2018, 10:06am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/2 "2018-09-14T10:06:21Z")

</div>

I dont think you should have ‘query=’ inside the SQLQuery

---

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [September 14, 2018, 10:13am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/3 "2018-09-14T10:13:36Z")

</div>

> [@kairongsen](#):
>
> SELECT Item\_Name, Item\_Weight, t\_stamp FROM container WHERE Storage\_Bay = {baypopup.bayNo}

This is my query. I think there is no 'query=' inside it

---

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [September 14, 2018, 10:16am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/4 "2018-09-14T10:16:27Z")

</div>

Once I change it to  
SELECT Item\_Name, Item\_Weight, t\_stamp FROM container WHERE Storage\_Bay = 1

It work perfectly but i need it to be indirect

---

<div class="post-metadata">

**Author:** ![Stuart](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Stuart](https://forum.inductiveautomation.com/u/Stuart)\
**Post date:** [September 14, 2018, 10:52am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/5 "2018-09-14T10:52:58Z")

</div>

Been awhile since I’ve done this… but try adding quotes around the `{baypopup.bayNo}` portion. Single I think, but maybe double.

---

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [September 14, 2018, 11:18am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/6 "2018-09-14T11:18:45Z")

</div>

Hi Stuart,

single quote and double quote cause no error but cant get data from database

---

<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 14, 2018, 12:13pm UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/7 "2018-09-14T12:13:58Z")

</div>

From the original error message, it appears that the property reference is being replaced with an empty string. That suggests a typo in the reference name or in the outer assignment from template holder to that property of the template.

---

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [September 17, 2018, 5:34am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/8 "2018-09-17T05:34:37Z")

</div>

Hi pturmel,

Thanks for trying to help.  
At the end it was my keyboard input problem. I change it back to default one and retype the quote symbol then everything work perfectly now.

---

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [September 17, 2018, 5:35am UTC](https://forum.inductiveautomation.com/t/fail-to-write-to-database-with-property-included-inside-the-sql-query/19670/9 "2018-09-17T05:35:36Z")

</div>

Hi Stuart,

At the end it was my keyboard input problem. I change it back to default and try with quote symbol again. It works. Thanks
