Dynamically generated SQL query in Retool

Try doing this as a JavaScript query that returns the statement, declare the statement in your SQL query and then EXEC(theStatement).

jsQuery:
return "select '111' from dual"
SQL:

DECLARE @statement NVARCHAR(max)
SET @statement = {{jsQuery.data}}
EXEC(@statement)

I see that you are trying to access a Oracle DB, so you might need to use a different declaration/execute syntax but I've been able to create dynamic queries (sanitized in the query as best as possible).

We have made some pretty interesting queries this way to be able to query through OPENQUERY to an Oracle linked server.

2 Likes