Skip to main content
Sep 9, 2020 10:37 AM UTC
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
Sep 9, 2020 8:19 PM UTC

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

 

select * from <<table_name>>

4 replies

Sep 9, 2020 1:01 PM UTC

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.

 

 

 

Sep 9, 2020 4:24 PM UTC

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 😉

nmillesonAnswer
Sep 9, 2020 8:19 PM UTC

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

 

select * from <<table_name>>

Sep 10, 2020 4:27 AM UTC

It works.

 

Thanks!