# Query browser reading tags to where condition

**URL:** <https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602>\
**Category:** Ignition\
**Created:** [August 30, 2022, 2:05pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602 "2022-08-30T14:05:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 30, 2022, 2:05pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602/1 "2022-08-30T14:05:42Z")

</div>

I am trying to read a tag into the query browser.  
Getting errors.  
I thought {} encapsulating the tag path was enough.

```auto
select top 1 Machine from SpecStandards
where Machine like concat('X',substring (
 str({[Main]Location/Sublocation/Machine/Model}),
1,len(str({[Main]Location/Sublocation/Machine/Model})-1))

```

---

<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:** [August 30, 2022, 2:08pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602/2 "2022-08-30T14:08:38Z")

</div>

I don’t think you can do that directly into a query browser. Make a test window and then make a sql query binding with the tag paths, or look at the actual values in the tags and put those into the query browser directly (instead of the tag reference).

Also, `str()` is a python thing, I don’t think any db uses that as a function keyword (though I may be wrong). Same with len. I know MySQL uses LENGTH() for instance.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 30, 2022, 2:12pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602/3 "2022-08-30T14:12:16Z")

</div>

SQL uses STR()

> [STR() Function in SQL Server - GeeksforGeeks](https://www.geeksforgeeks.org/str-function-in-sql-server/)

How do I read a tag in the query browser?

---

<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:** [August 30, 2022, 2:13pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602/4 "2022-08-30T14:13:14Z")

</div>

> [@zacharyw.larson](#):
>
> How do I read a tag in the query browser?

You can't.

You must either use values directly, or create a test view.

---

<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:** [August 30, 2022, 2:13pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602/5 "2022-08-30T14:13:20Z")

</div>

Oh ok nice. Just mentioned it as maybe an issue.

But I don’t think you can use tag references directly in the query browser tool. It would be nice but I don’t think that’s possible.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 30, 2022, 2:22pm UTC](https://forum.inductiveautomation.com/t/query-browser-reading-tags-to-where-condition/63602/6 "2022-08-30T14:22:16Z")

</div>

Edit for conciseness:

**What I am trying to do:**  
Read in a tag like, 310200 from the plc, and use a query to match with X310207 from a table.

```auto
select top 1 Machine from SpecStandards
where Machine like concat('X',ltrim(substring(str({[.]model2}),1,(len(str({[.]model2}))-1))))

```

Gives me null instead of X310207

```auto
select concat('X',ltrim(substring(str({[.]model2}),1,(len(str({[.]model2}))-1)))) from SpecStandards

```

This gives me the “X31020” as a tag value.

```auto
select 1 top Machine from SpecStandards
where Machine like '%{[.]model3}%'

```

This will give me “X310207” which is what I want.

However, I wanted to do it with just one query tag.

```auto
select top 1 Machine from SpecStandards
where Machine like '%concat('X',ltrim(substring(str({[.]model2}),1,(len(str({[.]model2}))-1))))%'

```

This errors.

* * *

Finally figured it out. Needed to concat the percent symbols, and didn’t need the ‘X’.

```auto
select top 1 Machine from SpecStandards
where Machine like concat('%',ltrim(substring(str({[.]model2}),1,(len(str({[.]model2}))-1))),'%')

```
