Skip to main content
1-Visitor
March 9, 2016
Question

How can I execute a sql query constructed dynamically?

  • March 9, 2016
  • 1 reply
  • 7200 views

Hi Team,

I am constructing a SQL query dynamically with varying number of columns.

After I construct this SQL query, How can I execute this to return an infotable?

Can you please share some sample code related to this.

Thanks & Regards,

Sunil

1 reply

22-Sapphire I
March 9, 2016

obviously this is very dangerous, but often necessary. so make sure you guard against sql injection

but you can setup an sql query that executes a string input. create another service that builds the sql statement and then call and feed that into the other service.

make sure to secure the service that actually executes the sql statement with the system user.

1-Visitor
March 10, 2016

I'm trying to do the same thing. I'd like to know how would you setup an sql query that executes a string input (which is the sql statement and is build dynamically).

Thanks

1-Visitor
March 10, 2016

Easy :

- create an sql service taking a part of your query or all of your query (if you want something generic [but dangerous as Pai said], put a string as parameter that you would name query and just put  <<query>> in your script).

- create a javascript service which will build the sql query as a string

- call the first service you created in the second one by putting the generated query string as parameter