Importing data from client tags in Scalar Prep Query

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 ="[Client]lang").value"[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)

[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.


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