# How to reference a tag's path in the SQL Query on that tag

**URL:** <https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762>\
**Category:** Ignition\
**Created:** [January 26, 2018, 10:59pm UTC](https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762 "2018-01-26T22:59:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [January 26, 2018, 10:59pm UTC](https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762/1 "2018-01-26T22:59:54Z")

</div>

I have a Query Tag and I would like to refer to the tag’s path in the query. Is this possible? I have tried a few syntaxes but I either get null/error or just the tag’s name and not its full path.

```auto
SELECT PreviousValue 
FROM Table 
WHERE TagPath = '{[.]ThisTag.Path}'

```

---

<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:** [January 27, 2018, 12:35pm UTC](https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762/2 "2018-01-27T12:35:25Z")

</div>

I think the only way you could do that would be to make the tag from a UDT and then reference the UDT specific parameters for PathToTag and PathToParentFolder.

[https://docs.inductiveautomation.com/display/DOC79/Creating+UDT+Definition](https://docs.inductiveautomation.com/display/DOC79/Creating+UDT+Definition)

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [January 29, 2018, 3:24pm UTC](https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762/3 "2018-01-29T15:24:36Z")

</div>

Thank you. I think for this particular project I won’t set up a UDF, but it’s good info to have for next time.

---

<div class="post-metadata">

**Author:** ![AFULLER](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/afuller/32/7931_2.png) [@AFULLER](https://forum.inductiveautomation.com/u/AFULLER)\
**Post date:** [March 2, 2021, 9:37pm UTC](https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762/4 "2021-03-02T21:37:54Z")

</div>

Where is the SQL reference in the UDT page you linked?

---

<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:** [March 2, 2021, 10:43pm UTC](https://forum.inductiveautomation.com/t/how-to-reference-a-tags-path-in-the-sql-query-on-that-tag/16762/5 "2021-03-02T22:43:19Z")

</div>

It would be a SQL Tag type in the UDT.  
Create a UDT with 2 parameters  
Param1 type String  
Param2 type String  
1 SQL Tag with the settings:  
DataSource – Set to {Param1}  
Query — SELECT \* FROM MyTable WHERE CriteriaColumn=’{Param2}’

Then you just create the instance of the UDT and fill in the parameters.
