# SQL query using variables

**URL:** <https://forum.inductiveautomation.com/t/sql-query-using-variables/10961>\
**Category:** Ignition\
**Created:** [December 27, 2015, 9:49pm UTC](https://forum.inductiveautomation.com/t/sql-query-using-variables/10961 "2015-12-27T21:49:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 27, 2015, 9:49pm UTC](https://forum.inductiveautomation.com/t/sql-query-using-variables/10961/1 "2015-12-27T21:49:14Z")

</div>

Hey guys, hope everyone is enjoying the holidays. quick question, so i’m trying something not sure if it will work but instead of having each OP send their end of the shift data(only one row of data with multiple columns of course) to a separate table, I’m sending them all(only 5 OPs) to one table.  
Whats the best way to include a variable in a SQL query so I can change the OP name like this:

```auto
WHERE
       EOS_Name = 'Shift A' AND OP = '{Root Container.Dropdown 1.selectedStringValue}' 
```

In the table I have OP100 OP101… so based on string value of a drop down I like to query different columns but I’m not quite sure how to do that where my string is actually a variable coming from a dropdown string value. I remember back in my JAVA days working with DB I used

```auto
'"+variable+"'
```

to put a variable inside a query but that was MYSQL and this is MS SQL so wasn’t sure if there is a different method… Thanks in advance.

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [December 27, 2015, 10:13pm UTC](https://forum.inductiveautomation.com/t/sql-query-using-variables/10961/2 "2015-12-27T22:13:44Z")

</div>

You’ve already got the right answer. 😃

I’ve got one open on my Designer now, doing exactly what you are wanting to do in MSSQL.

```auto
where Name = '{Root Container.Dropdown.selectedStringValue}' and SequenceDate = '{Line2/Run/Sequence Date}' 
```

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 28, 2015, 4:57pm UTC](https://forum.inductiveautomation.com/t/sql-query-using-variables/10961/3 "2015-12-28T16:57:26Z")

</div>

haha, the thing is, tables are empty so i guess i couldn’t test it correctly 😛, well lesson learned… more testing before asking 😃
