Skip to main content
1-Visitor
September 9, 2020
Solved

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

  • September 9, 2020
  • 3 replies
  • 3604 views

Hi,

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

Is it possible ?

Thanks,

Chahat

Best answer by nmilleson

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

 

select * from <<table_name>>

3 replies

5-Regular Member
September 9, 2020

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.

 

 

 

19-Tanzanite
September 9, 2020

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 😉

nmilleson17-PeridotAnswer
17-Peridot
September 9, 2020

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

 

select * from <<table_name>>

1-Visitor
September 10, 2020

It works.

 

Thanks!