1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
1.9K views
by mike-r-7535 (13.8k points)

I have the following code and am getting an "Incorrect syntax near 'null'" error when it runs.

var queryResult = qie.doQuery(
  "myDatabase",
  "select patmname, patdob, patsex, pataddr2, pataddr1, patcity, patstate, patzip\n" +
  "   from analyzer_tci.dbo.patdemo_t\n" +
  "   where acctno = ('" + messageCache.getValue('Acct Number') + "'");

Here is the error I receive

Why is it not working?

1 Answer

0 votes
 
Best answer
The approach I would take to this problem is to check if the account number is null before using it in the sql statement.  If the accountNumber is null, you should skip the query, and possibly error the message.  So something like this...
var accountNumber = messageCache.getValue('Acct Number');
if (accountNumber !== null) {
   var queryResult = qie.doQuery(
     "GPMS Analyzer_TCI",
     "select patmname, patdob, patsex, pataddr2, pataddr1, patcity, patstate, patzip\n" +
     "   from analyzer_tci.dbo.patdemo_t\n" +
     "   where acctno = '" + accountNumber + "'");
 
  // ... use the queryResult.getNode() to get the fields
} else {
  throw "AccountNumber is null.  Cannot perform lookup.";
}

 

by mike-r-7535 (13.8k points)
selected by mike-r-7535
...