SQL/MX Quick Start (G06.24+, H06.03+)

Stating Conditions for Selecting Data
HP NonStop SQL/MX Quick Start523724-002
3-2
Using the LIKE Predicate
Using the LIKE Predicate
Sometimes you want to select data that you are not able to specify completely. For
example, suppose you want to know something about a particular printer, but you
cannot remember the exact description of the printer.
Example
You do not know the exact name for a printer, but need to find its part number:
SELECT PARTNUM, PARTDESC
FROM PARTS
WHERE PARTDESC LIKE '%PRINTER%'
ORDER BY PARTNUM;
The selected rows are:
PARTNUM PARTDESC
------- ------------------
2001 GRAPHIC PRINTER,M1
2002 GRAPHIC PRINTER,M2
2003 GRAPHIC PRINTER,M3
2402 LASER PRINTER, T1
2403 LASER PRINTER, T2
2405 LASER PRINTER, T3
3103 LASER PRINTER, X1
6603 PRINTER CONTROLLER
--- 8 row(s) selected.
Tip
A percent sign (%) indicates zero or more characters are acceptable. An
underscore (_) indicates any single character is acceptable. For example,
'_RINTER' locates 'PRINTER' but not 'LINE PRINTER CONT.' The special
characters % and _ are called wild-card characters.
If you are not sure whether a value appears in uppercase or lowercase letters, use
the UPSHIFT function to convert lowercase letters in the part description to
uppercase before making the comparison:
SELECT PARTNUM, PARTDESC
FROM PARTS
WHERE UPSHIFT(PARTDESC) LIKE '%PRINTER%';
If it exists in the database, this row is selected:
8672 Laser printer