# SQL / Expression Code Help

**URL:** <https://forum.inductiveautomation.com/t/sql-expression-code-help/5052>\
**Category:** Ignition\
**Created:** [August 24, 2012, 6:00pm UTC](https://forum.inductiveautomation.com/t/sql-expression-code-help/5052 "2012-08-24T18:00:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlr573](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jlr573](https://forum.inductiveautomation.com/u/jlr573)\
**Post date:** [August 24, 2012, 6:00pm UTC](https://forum.inductiveautomation.com/t/sql-expression-code-help/5052/1 "2012-08-24T18:00:20Z")

</div>

I have a table on that is using this SQL statement;

[code]SELECT  
\*  
FROM  
dwg\_list

{Root Container.tblDwgList.whereClause}[/code]

Where Clause

`if({Root Container.txtDwgID.text} = "",
	 concat("WHERE cntlr_id =", {Root Container.drpCntlrName.selectedValue}),
	 	concat("WHERE dwg_id =", {Root Container.txtDwgID.text}))`  
Error

[code]Exception: Error running query:  
SQLQuery(query=SELECT  
\*  
FROM  
dwg\_list

WHERE dwg\_id =40\_1000-Layout1.pdf, database=)@5000ms  
On: Main Window 1.Root Container.tblDwgList.data  
caused by GatewayException: Unknown column ‘40\_1000’ in ‘where clause’  
caused by MySQLSyntaxErrorException: Unknown column ‘40\_1000’ in ‘where clause’

Ignition v7.5.0 (b1079)  
Java: Oracle Corporation 1.7.0\_05  
[/code]

When I type into the ‘Root Container.txtDwgID.text’ text box ‘40\_1000-Layout1.pdf’ i get the above error.

But if I change the SQL statement to

[code]  
SELECT  
\*  
FROM  
dwg\_list

WHERE dwg\_id =‘40\_1000-Layout1.pdf’[/code]

The query works

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [August 24, 2012, 7:25pm UTC](https://forum.inductiveautomation.com/t/sql-expression-code-help/5052/2 "2012-08-24T19:25:59Z")

</div>

To get the single quotes around your string, try:

`if({Root Container.txtDwgID.text} = "",
    concat("WHERE cntlr_id ='", {Root Container.drpCntlrName.selectedValue}),
       concat("WHERE dwg_id ='", {Root Container.txtDwgID.text})) + "'"`

Or:

`if({Root Container.txtDwgID.text} = "",
    concat("WHERE cntlr_id ='", {Root Container.drpCntlrName.selectedValue},"'"),
       concat("WHERE dwg_id ='", {Root Container.txtDwgID.text}, "'"))`

The first illustrates the + operator with strings. The second is a bit more clean, using 3 parameters with the concat function instead of 2.
