Be sure your where clause is defined using the correct number of apsotrophies: let $WhereClause = 'Where (A.HMRGP = ' || '''' || '01' || '''' let $WhereClause = $WhereClause || ' or A.HMRGP = ' || '''' || '15' || '''' || ')' I split this into two lines only for readability.