Sidebar

Is it possible use a variable in a DB query?

0 votes
660 views
asked Jun 24, 2015 by terrie-g-7436 (3,950 points)
I need to query a database using a variable as the selection criteria.

1 Answer

+1 vote
In a db query, the values in the WHERE statement must be surrounded by quote characters unless they are numeric. In order to use the value of a variable in a database query in QIE  you have to add the quote characters to the variable in the WHERE statement using the + character. Below is an example of the code.
 
// Declare the required variables
var lastName = message.getNode('RXA-10.2');
var firstName = message.getNode('RXA-10.3');
var suffix = message.getNode('RXA-10.5');
var login = (lastName + ' ' + suffix);
 
// To use the variables surround them with quotes(" + variable + ")
var queryResult = qie.doQuery(
      "CPS DB",
      "select loginName\n" +
      "from USR\n" +
      "where lastName = '" + login + "'\n" +
      "  and firstName = '" + firstName + "'");
      
      message.setNode('RXA[@9.1=00]-10.1', queryResult.getNode('loginName'));
answered Jun 24, 2015 by terrie-g-7436 (3,950 points)
...