# Importing data from client tags in Scalar Prep Query

**URL:** <https://forum.inductiveautomation.com/t/importing-data-from-client-tags-in-scalar-prep-query/12046>\
**Category:** Ignition\
**Created:** [August 19, 2016, 9:57am UTC](https://forum.inductiveautomation.com/t/importing-data-from-client-tags-in-scalar-prep-query/12046 "2016-08-19T09:57:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanko26](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@vanko26](https://forum.inductiveautomation.com/u/vanko26)\
**Post date:** [August 19, 2016, 9:57am UTC](https://forum.inductiveautomation.com/t/importing-data-from-client-tags-in-scalar-prep-query/12046/1 "2016-08-19T09:57:26Z")

</div>

Ladies and gents,

I have this script running on tag value change. It works fine if I define the column name manually but as soon as try to use value of a tag it displays the value of the tag rather than the information from that column and row in SQL. Thanks in advance!

lang is String  
tag is Integer

`lang = system.tag.read("[Client]lang").value
tag=system.tag.read("[Client]Last error 2").value
query = "SELECT ? FROM Last_stop_errors WHERE no=?"
data=system.db.runScalarPrepQuery(query,[lang,tag])
system.tag.write("[Client]Description 2", data) `

---

<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:** [August 19, 2016, 12:19pm UTC](https://forum.inductiveautomation.com/t/importing-data-from-client-tags-in-scalar-prep-query/12046/2 "2016-08-19T12:19:28Z")

</div>

[quote=“vanko26”]`query = "SELECT ? FROM Last_stop_errors WHERE no=?"
data=system.db.runScalarPrepQuery(query,[lang,tag])`[/quote]Type-safe parameter substitution with ‘?’ placeholders only works for the data elements in a query, not for the structure of the query. You’ll have to use python string substitution or some other python string composition for the column name. Like so:`query = "SELECT %s FROM Last_stop_errors WHERE no=?" % lang
data=system.db.runScalarPrepQuery(query,[tag])`Note that you are responsible for making sure the resulting query string is valid SQL.

---

<div class="post-metadata">

**Author:** ![vanko26](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@vanko26](https://forum.inductiveautomation.com/u/vanko26)\
**Post date:** [August 22, 2016, 7:59am UTC](https://forum.inductiveautomation.com/t/importing-data-from-client-tags-in-scalar-prep-query/12046/3 "2016-08-22T07:59:52Z")

</div>

Pturmel,

I have tried that way but must’ve had a syntax mistake somewhere. It works now. Thanks a lot!
