# Named Query with SQL Server

**URL:** <https://forum.inductiveautomation.com/t/named-query-with-sql-server/79234>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [September 15, 2023, 5:28pm UTC](https://forum.inductiveautomation.com/t/named-query-with-sql-server/79234 "2023-09-15T17:28:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 15, 2023, 5:28pm UTC](https://forum.inductiveautomation.com/t/named-query-with-sql-server/79234/1 "2023-09-15T17:28:04Z")

</div>

I would like to pass in a list of machines to filter my named query but I can't seem to get this to work.

> SELECT x,y,z  
> FROM my\_table  
> WHERE x in :machines

I have machines as a value type parameter and am passing this string in like ('M1','M2','M3')  
I have also tried moving the parenthesis to the query but no luck. Anyone know the best way to do this? I am trying to call this to get my dataset in a event script (Vision 8.1.25) The only way I have gotten the IN operator to work in the past like this was to construct the query using string concatenation but for this case I have a very long query and a bunch of different named queries to pick from conditionally so I thought it would make sense to use named queries here. If not, then I'll just construct it in the script like this

> includedMachinesString = ''  
> for m in includedMachines:  
> if len(includedMachinesString) == 0:  
> includedMachinesString = "'" + m + "'"  
> else:  
> includedMachinesString = includedMachinesString + ', ' + "'" + m + "'"  
> dsDeptTrend = None  
> if len(includedMachinesString) \> 0 :  
> includedMachinesString = '(' + includedMachinesString + ')'
> 
> ```
> queryTrend = '''SELECT t_stamp, x,y,z FROM my_table WHERE machine in ''' + includedMachinesString
> argsTrend = []
> trendDept = system.db.runPrepQuery(queryTrend, argsTrend, 'Ignition_DB')
> trendDept = system.dataset.toDataSet(trendDept)
> 
> ```

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 15, 2023, 5:35pm UTC](https://forum.inductiveautomation.com/t/named-query-with-sql-server/79234/2 "2023-09-15T17:35:28Z")

</div>

Well I think changing machines to a queryString has done the trick. I'm confirming now that I got what I am expecting but it looks right so far.
