I am trying to use DBEngine query() command to select data from MSSQL database and I need to pass parameter/s to my query. I am following this tech spec - DBEngine.query() documentation.
There is an example showing how to pass a param - to do this use $(l), $(sz) as a param-holder/s (depending on param type), then pass param value/s separated by comma. Easy.
However, when I do so I get an exception: Error: SCR-160021 Function 'query': too many arguments (X instead of 1).
Where X is 2 if I pass a single param. It's 3 if I pass two params. And so on. Only query text is possible to pass as a single allowed function argument.
This is my code lines:
var conn = application.getConnection(); result_Select = conn.query('SELECT 12345 as Col1, \'John Doe\') as Col2 WHERE 1 = $(l);', 1);
This is the exception:
Error: SCR-160021 Function 'query': too many arguments (2 instead of 1).
ACC v7.0 19.1 build 9032@d3b4522f of 01/07/2021.
Btw, the same problem for DBEngine.execute() command.
Is this a problem? Or I do something wrong?
Hello @igorku ,
There is issue in your query as highlighted below:
When I run the below query then it executed.
var cnx = application.getConnection()
result_Select = cnx.query('SELECT 12345 as Col1, \'John Doe\' as Col2 WHERE 1 = $(l);', 1);
Thank you for detecting extra symbol, but actually I don't have it in my code. Not sure what's the problem on my end but this is what I am seeing.
I would not recommend to use the DBEngine, you're exposing yourself to trouble down the line....
In your use case, why queryDef would work or Query activity in a workflow?