# Help Reducing a Query

**URL:** <https://forum.inductiveautomation.com/t/help-reducing-a-query/81922>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [November 15, 2023, 2:33pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922 "2023-11-15T14:33:05Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 15, 2023, 6:10pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/21 "2023-11-15T18:10:06Z")

</div>

> [@paul-griffith](#):
>
> `OR 1=1`

huh ?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 15, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/22 "2023-11-15T18:12:11Z")

</div>

> [@Ryan\_Craig](#):
>
> But after typing in a value for the MachineID, it returns Nulls:

Check for silly stuff. Have you a space after '`E373 `'?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 15, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/23 "2023-11-15T18:12:35Z")

</div>

> [@pascal.fragnoud](#):
>
> huh ?

Effectively makes the entire set of conditions a No-Op if none of the options are provided. Not terrific for performance.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 15, 2023, 6:13pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/24 "2023-11-15T18:13:51Z")

</div>

Probably want to `trim()` the parameter input and the column values itself to avoid this to avoid cases where the user adds a space, or if the data itself has an extraneous one.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 15, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/25 "2023-11-15T18:17:45Z")

</div>

From what I see, it makes the whole where clause useless: everything in it is always going to be true.  
Or am I reading this wrong ?

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [November 15, 2023, 6:19pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/26 "2023-11-15T18:19:21Z")

</div>

Can't seem to find exactly what is happening but if I use 'E373%' it seems to work.  
Would that have potential to cause any issues in the future, or would that be ok to use?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 15, 2023, 6:24pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/27 "2023-11-15T18:24:52Z")

</div>

> [@Ryan\_Craig](#):
>
> if I use 'E373%' it seems to work.

That suggests that there are trailing spaces in the database columns. Try modifying the query to remove these using the TRIM function:

```auto
FROM [TransactionGroup].[dbo].[AQVision_Cognex]
	WHERE TRIM(PartNumber) LIKE :partNumber 
	WHERE TRIM(MachineID) LIKE :machineID
	WHERE DateTime BETWEEN :startDate AND :endDate 

```

While ``E373%` might work now it could bite someone later if there are variants. I wouldn't.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 15, 2023, 6:30pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/28 "2023-11-15T18:30:07Z")

</div>

No, you're correct, that's what I am saying. The query suggested by chatGPT is incorrect, because `OR 1=1` turns the entire WHERE clause into a No-Op. So if that query was used it would always return all rows, and have horrible performance because SQL would still perform the evaluations.

Sorry, wasn't clear in my post, was actually expanding on your question and stating why it makes no sense.

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [November 15, 2023, 6:38pm UTC](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922/29 "2023-11-15T18:38:28Z")

</div>

Seems like this all worked. The pie charts and tables seem to be working much better and faster. Thanks for the help!

[Previous page](https://forum.inductiveautomation.com/t/help-reducing-a-query/81922.md?page=1)
