# Tag read scripting help

**URL:** <https://forum.inductiveautomation.com/t/tag-read-scripting-help/5567>\
**Category:** Ignition\
**Created:** [December 12, 2012, 4:11pm UTC](https://forum.inductiveautomation.com/t/tag-read-scripting-help/5567 "2012-12-12T16:11:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [December 12, 2012, 4:11pm UTC](https://forum.inductiveautomation.com/t/tag-read-scripting-help/5567/1 "2012-12-12T16:11:06Z")

</div>

Can someone please tell me why this code is having trouble with the declared variable LimVal?  
Are we not correctly referencing the variable after LIMIT?

LimVal = system.tag.read(“LINE 1/Tag\_BO3\_28\_0-28\_15\_Int”).value  
query=“SELECT L1\_SECA\_ITEM FROM L1\_DRYER\_TRACK ORDER BY t\_stamp desc LIMIT (LimVal)”  
table1 = system.db.runQuery(query,“PM\_DATA”)

Thanks

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [December 12, 2012, 4:19pm UTC](https://forum.inductiveautomation.com/t/tag-read-scripting-help/5567/2 "2012-12-12T16:19:09Z")

</div>

You need to use Python string substitution to get the variable added to the query string:

`LimVal = system.tag.read("LINE 1/Tag_BO3_28_0-28_15_Int").value
query="SELECT L1_SECA_ITEM FROM L1_DRYER_TRACK ORDER BY t_stamp desc LIMIT %s" % (LimVal)`

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [December 12, 2012, 4:20pm UTC](https://forum.inductiveautomation.com/t/tag-read-scripting-help/5567/3 "2012-12-12T16:20:33Z")

</div>

The syntax is just a little off:`LimVal = system.tag.read("LINE 1/Tag_BO3_28_0-28_15_Int").value
query="SELECT L1_SECA_ITEM FROM L1_DRYER_TRACK ORDER BY t_stamp desc LIMIT %d" % LimVal
table1 = system.db.runQuery(query,"PM_DATA")`

---

<div class="post-metadata">

**Author:** ![scott\_stc](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@scott\_stc](https://forum.inductiveautomation.com/u/scott_stc)\
**Post date:** [December 12, 2012, 4:59pm UTC](https://forum.inductiveautomation.com/t/tag-read-scripting-help/5567/4 "2012-12-12T16:59:36Z")

</div>

Thank you, James and Travis. That worked beautifully!
