SQL/MP Query Guide
Retrieving Data: How to Write Queries
HP NonStop SQL/MP Query Guide—524488-003
1-35
Predicates Connected by OR Operators
Using LIKE With TRIM
You can use LIKE in combination with TRIM to do comparisons. This combination is 
useful when the host variable is fixed length and the pattern to match is shorter than 
the length of the host variable. 
In this example, :hostvar contains the value “ROB% ” (padded with three 
blanks): 
CREATE TABLE NAMES (FIRST_NAME VARCHAR (10)) ;
INSERT INTO NAMES VALUES ("ROBERT") ;
INSERT INTO NAMES VALUES ("ROB") ;
INSERT INTO NAMES VALUES ("ROBBIE") ;
INSERT INTO NAMES VALUES ("PEDRO") ;
SELECT FIRST_NAME FROM NAMES 
 WHERE (FIRST_NAME) LIKE TRIM (:hostvar) ;
SQL selects the first three rows because :hostvar is trimmed to “ROB%” and the % 
wild card directs SQL to select all NAMEs whose values begin with “ROB” and have 
any or no trailing characters.
For information on TRIM, see Removing Leading or Trailing Characters From a String 
on page 1-19.
Using LIKE Efficiently
Some formulations of LIKE predicates are more efficient than others. For more 
information, see Using LIKE Predicates on page 3-24.
For more information on LIKE, see the SQL/MP Reference Manual.
Predicates Connected by OR Operators
You can use the OR operator to connect predicates. You might want to use the OR 
operator, for example, to select a set of rows that have different values in the same 
column or to compare values in different columns. 
In this example, the OR operator is used to select information about two employees 
from the database:
SELECT EMP_ID, LAST_NAME, FIRST_NAME, DEPT_NUM, MGR_ID
 FROM EMPLOYEE
 WHERE EMP_ID = 2705 OR EMP_ID = 2906 ;










