When you do more than one calculation within a numeric expression, use parentheses to tell Query in what order to do the calculations and to make the expression easier to understand. If you use nested parentheses for example, 60 * (A − (B + C)), the calculations are done for the innermost pair first (in the example, B + C), then the next innermost pair, and so on. If you do not use parentheses, Query first does multiplication and division, left to right, and then addition and subtraction, left to right. For example, (5 +
4)* 2 equals 18, but 5 + 4 * 2 equals 13.
Be aware that the result of a numeric expression, especially one containing division and multiplication operations, is truncated or rounded depending on what you specify on the Specify Processing Options display (see Chapter 14, “Specifying Query for iSeries processing options”). If you divide by zero, your query may not run.
Query for iSeries character expressions
To define a character result field (that is, a result field that contains SBCS or DBCS characters) for your query, you need to follow the rules for creating character expressions. A character expression for a result field can contain the following, alone or in combination:
vCharacter field names (names of fields that contain SBCS or DBCS characters). You can use the names of SBCS- or
vCharacter constants (SBCS or DBCS characters enclosed in apostrophes, such as ’ABCdef123’ or
’This text includes blanks and special characters **$$’). The rules for using character constants are:
–The character constant must be enclosed in apostrophes.
–Any combination of letters, numbers, or special characters (for example, $ or #) can be used.
–If two apostrophes are used within a character string, the two apostrophes become a single apostrophe in the output. For example, ’October’s Profits’ becomes October’s Profits.
–Words with lowercase and uppercase letters are used exactly as typed.
–If a character constant represents a valid date, time, or timestamp, and is used with a date, time, or timestamp field, it is considered a date, time, or timestamp constant.
–A DBCS character constant must include DBCS
vCharacter operators and functions (one or more concatenation operations and character functions SUBSTR, DIGITS, and
Query for iSeries concatenation operation
Character expressions can include one or more concatenation operations. Concatenation operations must be specified in the form:
v
vTwo logical OR symbols () make up the concatenation operator used to join the two values. (See
“CCSID and result field expressions in Query for iSeries” on page 252 to see how CCSIDs are handled for the concatenation symbol.)