# Using a querystring parameter in a named query IN clause

**URL:** <https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534>\
**Category:** Ignition\
**Tags:** namedqueries, ignition80\
**Created:** [June 7, 2021, 9:47pm UTC](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534 "2021-06-07T21:47:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [June 7, 2021, 9:47pm UTC](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534/1 "2021-06-07T21:47:35Z")

</div>

I have a query I’m converting to a named query. One parameter is an INT4, another a string.  
The string parameter can have one of three values: (‘site1’), (‘site2’) or (‘site1’,‘site2’).  
In the named query I am attempting to use the string parameter as follows:

…WHERE a.site IN ‘{site}’

If I test with the value “(‘site1’)” – not sending in the double quotes – it returns this error:  
GatewayException: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ‘site1’.  
I have tested any number of other permutations, but cannot find a way to make this work. I can format the string supplied as a parameter any way necessary, if anyone can advise. thanks

---

<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:** [June 7, 2021, 10:32pm UTC](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534/2 "2021-06-07T22:32:09Z")

</div>

Some databases do not accept single-value IN clauses.

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [June 7, 2021, 10:55pm UTC](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534/3 "2021-06-07T22:55:36Z")

</div>

I neglected to mention it is MS SQL Server 2018. So, a query like

SELECT someColumn FROM someTable WHERE site IN (‘site1’) will work.

Thanks, David

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [June 8, 2021, 1:15am UTC](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534/4 "2021-06-08T01:15:47Z")

</div>

> [@David](#):
>
> …WHERE a.site IN ‘{site}’

Have you tried without the quotes around `{site}`? These quotes will wrap your passed in list, turning it into a string instead of a list.

And since you are using curly braces, I'm assuming you already have the type set to `QueryString` for your `site` parameter?

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [June 8, 2021, 3:12pm UTC](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534/5 "2021-06-08T15:12:08Z")

</div>

I gave up on fiddling with that and rewrote my query as follows:

SELECT 0 as ‘Select’  
,itemId  
,itemNumber  
,description  
,CASE WHEN (SELECT COUNT(\*) FROM dbo.v\_ivInventory i  
**INNER JOIN dbo.fnT\_SplitVarchar(:site,’,’,‘0’) a ON i.site = a.item**  
WHERE w.itemId = i.itemId  
–and i.site IN ({site}  
) \> 1 THEN ‘Yes’  
ELSE ‘No’ END AS i  
FROM dbo.v\_imItem w  
WHERE itemClassId = :itemClassId  
order by i desc, itemId ASC

I changed the parameter from querystring to value, and this works. Thanks.
