# View() expression function where clause not working

**URL:** <https://forum.inductiveautomation.com/t/view-expression-function-where-clause-not-working/44361>\
**Category:** Ignition\
**Created:** [March 11, 2021, 1:33pm UTC](https://forum.inductiveautomation.com/t/view-expression-function-where-clause-not-working/44361 "2021-03-11T13:33:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gfeiten](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@gfeiten](https://forum.inductiveautomation.com/u/gfeiten)\
**Post date:** [March 11, 2021, 1:33pm UTC](https://forum.inductiveautomation.com/t/view-expression-function-where-clause-not-working/44361/1 "2021-03-11T13:33:54Z")

</div>

I’ve been starting to use pturmel’s view() function to filter data from a tag dataset. In short I have one broad query that supplies data for numerous table objects in perspective. I’m trying to avoid having each table object execute a slightly different query to the database.

The select works fine but I am getting zero rows every time I put in a where clause. I started with this expression:  
view(“Select Plant Where Plant ==‘S’”,{[default]query\_data/master\_data} )  
Plant has three values; P, S, and T. Although there are numerous instances of ‘S’, I get zero rows returned.

If I modify the expression to ‘not equal’:  
view(“Select Plant Where Plant !=‘S’”,{[default]query\_data/master\_data} )  
I get all rows returned (P, S, and T values), so it is definitely and issue with the equality expression.

I guessed there may be a data type issue so I changed the expression to:  
view(“Select Plant, type(Plant), type(‘S’)”,{[default]query\_data/master\_data} )  
This reveals that Plant is of type PyUnicode and ‘S’ is of type PyString.

So I validate I can use the str() function to convert Plant to PyString and try this:  
view(“Select Plant Where str(Plant)== ‘S’”,{[default]query\_data/master\_data} )…no dice.

Finally I tried storing the value ‘S’ in a memory tag (tried both text and string data types) and used it as an argument.  
view(“Select Plant Where Plant == args[0]”,{[default]query\_data/master\_data}, ({[default]query\_data/character\_S.value}) )  
same result.

I am out of ideas…any thoughts on what I could be doing wrong???

---

<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:** [March 11, 2021, 1:52pm UTC](https://forum.inductiveautomation.com/t/view-expression-function-where-clause-not-working/44361/2 "2021-03-11T13:52:02Z")

</div>

Is there any chance your raw dataset has trailing spaces on `Plant` ?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 11, 2021, 2:03pm UTC](https://forum.inductiveautomation.com/t/view-expression-function-where-clause-not-working/44361/3 "2021-03-11T14:03:47Z")

</div>

I’ve run into trailing spaces in IBM db2 databases (which may be an AS400/RPG problem). I have to use trim a lot.

```auto
trim(field)

```

---

<div class="post-metadata">

**Author:** ![gfeiten](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@gfeiten](https://forum.inductiveautomation.com/u/gfeiten)\
**Post date:** [March 11, 2021, 2:16pm UTC](https://forum.inductiveautomation.com/t/view-expression-function-where-clause-not-working/44361/4 "2021-03-11T14:16:30Z")

</div>

I’m so mad I didn’t think of that…  
view(“Select \* Where Plant.strip() == ‘S’”,{[default]query\_data/master\_data}, ({[default]query\_data/character\_S.value}) )  
nailed it.

Thanks!!!
