I have the same question. I want to find embedded percent signs as well as embedded apostrophes within a text field using AS/400 Query. Some of our text fields contain only a % or an ' and I want to use the LIKE.
You use the ESCAPE clause in the SQL statement to declare a symbol to mark the special character as a literal character.
SELECT * FROM TABLE WHERE C1 LIKE '%+%%' ESCAPE '+'
first '%' is wild card, '+%' is a character literal of a percent sign, and the third '%' is wild card; therefore, above will find any row where C1 contains a percent sign
I want to know if it is possible to do in AS/400 Query, not SQL
A SQL query is an AS/400 query; there are many kinds of AS/400 queries. If you mean that you actually want to use the old, practically obsolete, inefficient Query/400 or Query for iSeries product, I don't know of a good way to escape the '%' symbol without using SQL. (V5R3 at least can show "Query" as the product name in the list of installed products.) One might exist; I just haven't seen one.
The best answer is simply not to keep using the old query product for anything new, and convert old queries to new ones. (That doesn't apply to the recent Web Query product.)
Some of our text fields contain only a % or an ‘ and I want to use the LIKE.
If a field contains only a percent or apostrophe symbol, the LIKE function shouldn't be used. Just use "equal".
Tom
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 8  Replies