# NamedQuery help

**URL:** <https://forum.inductiveautomation.com/t/namedquery-help/89138>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [April 19, 2024, 7:49pm UTC](https://forum.inductiveautomation.com/t/namedquery-help/89138 "2024-04-19T19:49:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 19, 2024, 7:49pm UTC](https://forum.inductiveautomation.com/t/namedquery-help/89138/1 "2024-04-19T19:49:04Z")

</div>

Good day, I have this named query:

```python
SELECT TOP (1) *
FROM Buggy_Corral_Contents
WHERE 
     Lot_Num LIKE :LotLabel1
    OR
    Lot_Num LIKE :LotLabel2
    OR
    Lot_Num LIKE :LotLabel3
    OR
    Lot_Num LIKE :LotLabel4

```

That populates a table. My issue is when I have 4 parameters to pass in it returns results but when I have anything but, it doesnt return results. How can I modify this return even if there is less parameters to pass in? The parameters come from a label that looks like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/3/c3ae784f99dd08a1e7ff80c0d2fb480cab7ac2d6.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/a/da33f59bcd55ac4837195575fdd6879041aa04f5.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/9/a9ca0a368387e618259abdf4b67adadf66c5e8e1.png)

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [April 19, 2024, 7:58pm UTC](https://forum.inductiveautomation.com/t/namedquery-help/89138/2 "2024-04-19T19:58:16Z")

</div>

Like is a pretty poor parameter in sql.  
If the lots are actually equal then you can do the query as

`WHERE Lot_Num IN (:LotLabel1,:LotLabel2,:LotLabel3,:LotLabel4)`

---

<div class="post-metadata">

**Author:** ![Bushmatic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bushmatic/32/87014_2.png) [@Bushmatic](https://forum.inductiveautomation.com/u/Bushmatic)\
**Post date:** [April 19, 2024, 8:16pm UTC](https://forum.inductiveautomation.com/t/namedquery-help/89138/3 "2024-04-19T20:16:28Z")

</div>

Wrap each LIKE parameter in the SQL wildcard character, which is the percent sign ( `%` ). Instead of querying for `LIKE 'O5311G16'`, you will need to query for `LIKE '%O5311G16%'`. This means, if there is no lot number inputted, it will filter the query to only find things `LIKE '%%'`, which is the same thing as not filtering at all. Hopefully this makes sense. You may need to play around with the formatting of the named query or the script transform to get that to work, maybe by changing "Value" to "QueryString" in the named query authoring section or by adding some lines of code to modify your lot numbers before passing into the named query.

> **[SQL Wildcard Characters](https://www.w3schools.com/sql/sql_wildcards.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2024, 12:02am UTC](https://forum.inductiveautomation.com/t/namedquery-help/89138/4 "2024-04-21T00:02:44Z")

</div>

Well, I tried both suggestions and I am still not returning results. I appreciate the ideas but need some more help. I was wondering if I could do something like this:

```python
if({../LotLabel.props.text[2]} = null,'No Lot',{../LotLabel.props.text[2]})

```

That way if there was only 2 lots and not a third then it would make the missing lot 'No Lot', so it would atleast have some value to filter off of. BUT the expression returns a Bad\_Stale error.

Anyway around that?

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2024, 12:36am UTC](https://forum.inductiveautomation.com/t/namedquery-help/89138/5 "2024-04-21T00:36:35Z")

</div>

I found a solution. Its not ideal but it works and needed it to, lol.
