Skip to main content
1-Visitor
Solved

Is there a way to pass dynamic table name to sql query ?

Hi,

I want to pass the table name dynamically to SQL query in thingworx version 8.5.5

Is it possible ?

Thanks,

Chahat

nmillesonAnswer
17-Peridot

If you pass the parameter with <<param>> instead of [[param]] it should work.  E.g.

 

select * from <<table_name>>

4 replies

5-Regular Member

I am not sure if you will be able to pass the table name as an input to a SQL query service. But you can wrap different condition sql query service in a JS service using if/else. Like if the input is TableA, call the select * from TableA or else if it is TableB call the select * from TableB service. The Grid can handle dynamic data shape as well.

 

 

 

Translate
19-Tanzanite

In JDBC passing the table name as an SQL parameter is not possible.

You can create your own stored procedure for which there are examples in stackoverflow, but it leaves you open to SQL injection - and you don't want that.

I would follow my colleague's suggestion 😉

Translate
nmilleson17-PeridotAnswer
17-Peridot

If you pass the parameter with <<param>> instead of [[param]] it should work.  E.g.

 

select * from <<table_name>>

Translate
1-Visitor

It works.

 

Thanks!

Translate