AS400中WRKQRY如何用CONCAT匹配含制表符的文本字段?
How to Find Rows with Tab Characters in WRKQRY (AS/400)
Got it, since you already have the STRSQL logic working, let's translate that into WRKQRY's interactive record selection rules. Here are two straightforward methods to make this happen:
Method 1: Use the POSITION Function (Simpler Check)
This method checks if a tab character (CHR(9)) exists anywhere in your text field by looking for its position:
- Open WRKQRY and either create a new query or edit an existing one.
- After selecting your target library and table, navigate to the Select Records screen (from the Define Query menu, choose option 3).
- Press
F6=Add conditionto create a new selection rule. - Instead of picking a field directly, press
F11=Display expressionsto enter a custom condition. - Enter this expression (replace
YOUR_FIELDwith your actual text field name):POSITION(CHR(9) IN YOUR_FIELD) > 0CHR(9)generates the tab character (matches what you used in STRSQL).POSITION()returns the index of the tab in the field; if it's greater than 0, the tab exists.
- Save the condition, finish setting up your query (like selecting which fields to display), and run it. You'll get all rows where the field contains a tab.
Method 2: Replicate the STRSQL LIKE Logic
If you prefer to mirror your original STRSQL query, WRKQRY uses || as the concatenation operator (instead of CONCAT):
- Follow steps 1-3 from Method 1 to get to adding a new condition.
- In the condition setup:
- For Field, select your text field.
- For Comparison, choose
LIKE. - For Value, enter this expression:
'%' || CHR(9) || '%' - This concatenates wildcards (
%) around the tab character, just like your STRSQL query.
- Save and run the query—this will behave exactly like your STRSQL statement.
Quick Notes
- Make sure your field is a character/text type (not numeric or date) since we're checking for text characters.
- If
CHR(9)didn't work for some reason (unlikely since your STRSQL works), confirm your system's tab character code—EBCDIC systems sometimes useCHR(5), but your existing query provesCHR(9)is correct for your environment.
内容的提问来源于stack exchange,提问作者Wilson Pauly
相关产品推荐
相关产品推荐

