Skip to main content
1-Visitor
Mar 9, 2016 2:51 PM UTC
Question

How can I execute a sql query constructed dynamically?

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

8 replies

22-Sapphire I
Mar 9, 2016 4:31 PM UTC

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.

Translate
1-Visitor
Mar 10, 2016 8:10 AM UTC

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

Translate
1-Visitor
Mar 10, 2016 8:16 AM UTC

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

Translate