# SQL Query Lookup

**URL:** <https://forum.inductiveautomation.com/t/sql-query-lookup/4773>\
**Category:** Ignition\
**Created:** [July 5, 2012, 5:53pm UTC](https://forum.inductiveautomation.com/t/sql-query-lookup/4773 "2012-07-05T17:53:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drettberg](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@drettberg](https://forum.inductiveautomation.com/u/drettberg)\
**Post date:** [July 5, 2012, 5:53pm UTC](https://forum.inductiveautomation.com/t/sql-query-lookup/4773/1 "2012-07-05T17:53:34Z")

</div>

I want to filter a SQL Query on a table using the 2nd column of the selected item in a list.

SELECT a\_LongName  
FROM Employee  
WHERE HomeLocation\_ID =  
{Root Container.Locations.data}[{Root Container.Locations.data},1]

This syntax gets accepted but the query fails with the following message:

Exception: Error running query:  
SQLQuery(query=SELECT a\_LongName  
FROM Employee  
WHERE HomeLocation\_ID =  
Dataset [4R ⅹ 2C][Dataset [4R ⅹ 2C],1], database=VehicleDb)@0ms  
On: Main Window 3.Root Container.Table.data  
caused by GatewayException: Incorrect syntax near ‘4R ⅹ 2C’.  
caused by SQLServerException: Incorrect syntax near ‘4R ⅹ 2C’.

What syntax should I use?

Thanks,  
Dave

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 5, 2012, 6:10pm UTC](https://forum.inductiveautomation.com/t/sql-query-lookup/4773/2 "2012-07-05T18:10:37Z")

</div>

Hi Dave,

I usually stick the value from the list into a dynamic property, then use the dynamic property in the query. That way, I’m pretty sure what value is going into my script.

Also, I noticed that you you are using the .data as your row pointer. I’m guessing you were wanting to use .selectedIndex…

---

<div class="post-metadata">

**Author:** ![drettberg](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@drettberg](https://forum.inductiveautomation.com/u/drettberg)\
**Post date:** [July 5, 2012, 6:37pm UTC](https://forum.inductiveautomation.com/t/sql-query-lookup/4773/3 "2012-07-05T18:37:26Z")

</div>

That worked great!

Thanks.
