# SQL Query with realtime tag values

**URL:** <https://forum.inductiveautomation.com/t/sql-query-with-realtime-tag-values/23467>\
**Category:** Ignition\
**Created:** [March 19, 2019, 9:42pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-realtime-tag-values/23467 "2019-03-19T21:42:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshdunstan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joshdunstan/32/43306_2.png) [@joshdunstan](https://forum.inductiveautomation.com/u/joshdunstan)\
**Post date:** [March 19, 2019, 9:42pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-realtime-tag-values/23467/1 "2019-03-19T21:42:15Z")

</div>

With the query below, I’d like to use it to build a table that shows be both an offline (DB) and online (PLC) value for some recipe management. I’d like to do this with a query alone but am having issues getting a dynamic tag to resolve. Any help would be greatly appreciated, I’m hoping it’s just semantics.

SELECT  
s.id,  
p.name,  
s.value as offline,  
‘{Control/Axis/’ || ‘{Root Container.data::Meta.TagName}’ || ‘/stParameters/’ || p.tag || ‘}’ as online,  
u.unit,  
s.usersave,  
s.datesave   
FROM  
data\_element\_settings as s LEFT JOIN  
data\_element as e on s.elementid = e.id LEFT JOIN  
data\_element\_params as p on s.paramid = p.id LEFT JOIN  
data\_element\_params\_units as u on p.unitsid = u.id  
WHERE  
e.tag = ‘{Root Container.data::Meta.TagName}’

---

<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 19, 2019, 9:49pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-realtime-tag-values/23467/2 "2019-03-19T21:49:19Z")

</div>

Your database doesn’t have access to your tags. You can only get back from your DB what it holds and what you pass to it. What you _ **can** _ do is reprocess the dataset after it arrives from the DB to pick up values from Ignition. This requires scripting and/or functions like [view()](https://www.automation-pros.com/simaids/doc/expression.view.html) from [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids).

---

<div class="post-metadata">

**Author:** ![joshdunstan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joshdunstan/32/43306_2.png) [@joshdunstan](https://forum.inductiveautomation.com/u/joshdunstan)\
**Post date:** [March 19, 2019, 9:51pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-realtime-tag-values/23467/3 "2019-03-19T21:51:18Z")

</div>

Hey Phil, thanks, I understand that.

Ignition resolves a tag value in the query if its bound by ‘{…}’, I just haven’t had success dynamically building the tag path with a value from the database, was hoping to avoid writing on entry or timed code.

Thanks!

---

<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 19, 2019, 9:55pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-realtime-tag-values/23467/4 "2019-03-19T21:55:44Z")

</div>

> [@joshdunstan](#):
>
> I just haven’t had success dynamically building the tag path with a value from the database

The DB can't do that. The braces are completely resolved in Ignition _ **before** _ the SQL is sent to the DB -- there's no mechanism or opportunity to do what you are attempting. Also, you can't use _ **any** _ operators inside the braces. Ignition only allows a single tag path or component path or property name inside braces, and no nesting.
