...
Calculating the date difference in Query is done by creating an expression. This will calculate the year difference between the two dates in years, 365 being the number of days in a year.
...
The following images illustrate the substring using Expressionfunction in Expressions:
Expression:
Panel |
---|
substr (NATIONAL_ID, 6, 4) |
...
In the Expression Type field, select character. In the length field, enter 45 (the first byte for the hyphen). In the Expression Text, enter the phase mentioned above.
...
Decode
What Expression Does:
This allows the query to convert a database value to something more meaningful. For instance, if the query needs to display the class schedule with days of the weeks rather than a 'Y' or 'N' flags.
The following images illustrate the decode function in Expressions:
Expression:
Panel |
---|
decode (E.MON, 'Y', 'Mo') || decode (E.TUES, 'Y', 'Tu') || decode (E.WED, 'Y', 'We') || decode (E.THURS, 'Y', 'Th') || decode (E.FRI, 'Y', 'Fr') || decode (E.SAT, 'Y', 'Sa') || decode (E.SUN, 'Y', 'Su') |
How to create:
In the Expression Type: field, select character. In the length field, enter 14, to allow two bytes for each day of the week (7 x 2). In the Expression Text, enter the phase mentioned above
This converts the 'Y' value into a day of the week. The 'N' value is ignored. The '||' (double bar) is the concatenate symbol. You may type in the field name (don't forget the prefix) or press the Add Field link to search for the field. Press OK when you are done.
Note Remember to use the field/expression in your report. So instead of seven columns with 'Y' or 'N', the query will print something like 'MoWeFr'. An example of decode:
Decode
What Expression Does:
This allows the query to convert a database value to something more meaningful. For instance, if the query needs to display the class schedule with days of the weeks rather than a 'Y' or 'N' flags.
The following images illustrated calculation of date using Expression:
Expression:
Panel |
---|
decode (E.MON, 'Y', 'Mo') || decode (E.TUES, 'Y', 'Tu') || decode (E.WED, 'Y', 'We') || decode (E.THURS, 'Y', 'Th') || decode (E.FRI, 'Y', 'Fr') || decode (E.SAT, 'Y', 'Sa') || decode (E.SUN, 'Y', 'Su') |
How to create:
In the Expression Type: field, select character. In the length field, enter 14, to allow two bytes for each day of the week (7 x 2). In the Expression Text, enter the phase mentioned above
This converts the 'Y' value into a day of the week. The 'N' value is ignored. The '||' (double bar) is the concatenate symbol. You may type in the field name (don't forget the prefix) or press the Add Field link to search for the field. Press OK when you are done.
Note Remember to use the field/expression in your report. So instead of seven columns with 'Y' or 'N', the query will print something like 'MoWeFr'. An example of decode:
TO_CHAR
What Expression Does:
This allows the query to convert a number to a character field.
The following images illustrate the conversion of a number to a character using Expressionin Expressions:
Expression:
Panel |
---|
decode to_char (EA.MONENRL_CAP, 'Y', 'Mo') || decode (E.TUES, 'Y', 'Tu') || decode (E.WED, 'Y', 'We') || decode (E.THURS, 'Y', 'Th') || decode (E.FRI, 'Y', 'Fr') || decode (E.SAT, 'Y', 'Sa') || decode (E.SUN, 'Y', 'Su')9990.') |
How to create:
In the Expression Type: field, select character. In the length field, enter 14, to allow two bytes for each day of the week (7 x 2)length of your field - allow for decimals. In the Expression Text, enter the phase mentioned above
This converts the 'Y' value into a day of the week. The 'N' value is ignored. The '||' (double bar) is the concatenate symbol. You may type in the field name (don't forget the prefix) or press the Add Field link to search for the field. Press OK when you are done.Note Remember to use the field/expression in your report. So instead of seven columns with 'Y' or 'N', the query will print something like 'MoWeFr'. An example of decodeto_char: