Suppose you have a query management query that looks like the
following.
Select * From Customer Where CuName = &var
There are two ways you can be tripped up here. First, query manager is
case sensitive with respect to variable names. So if you invoke this
query as follows...
RunQmQry whatever SetVar( var 'A&P Grocery' )
1) Since the variable was defined as lower case in the query and since
the AS/400 command line monitor converts all names to upper case, the
variable var will be converted to VAR which doesn't match the name of
any variable in the query. The solution to this problem would be the
following query.
RunQmQry whatever SetVar( 'var' 'A&P Grocery' )
But we still have one more problem to solve.
2) The above query will attempt to run the following SQL command
Select * From Customer Where CuName = A&P Grocery
The problem here is there are no apostrophes surrounding the string
A&P Grocery as SQL syntax demands. In order to solve this problem, you
must use two apostrophes wherever you want the command line monitor to
pass a single apostrophe to the query. So the final solution to the
problem would look like this.
RunQmQry whatever SetVar( 'var' '''A&P Grocery''' )
Notice it takes 3 opening and closing apostrophes to solve the
problem. The first apostrophe is simply the one the command line
monitor needs in order to pass embedded special characters. The second
and third apostrophe tell the command line monitor to pass an
apostrophe. Similarly for the closing 3 apostrophes.
Mike Cravitz
NEWS/400 Technical Editor