Functions
- Last Updated: October 5, 2020
- 1 minute read
- DataDirect Connectors
- ODBC
- Cloudera Impala 7.1
- dBase 7.1
- Flat files/Text 7.1
- MySQL 7.1
- Pervasive (Btrieve) 7.1
- XML 7.1
- Documentation
The flat-file drivers support a number of functions that you may use in expressions. In the following tables, the functions are grouped according to the type of result they return.
| Function | Description |
|---|---|
| CHR | Converts an ASCII code into a one-character
string.
|
| RTRIM | Removes trailing blanks from a
string.
|
| TRIM | Removes trailing blanks from a
string.
|
| LTRIM | Removes leading blanks from a
string.
|
| UPPER | Changes each letter of a string to
uppercase.
|
| LOWER | Changes each letter of a string to
lowercase.
|
| LEFT | Returns leftmost characters of a
string.
|
| RIGHT | Returns rightmost characters of a
string.
|
| SUBSTR | Returns a substring of a string. Parameters are the
string, the first character to extract, and the number of characters to extract
(optional).
|
| SPACE | Generates a string of blanks.
|
| DTOC | Converts a date to a character string. An optional second
parameter determines the format of the result: 0 (the default) returns MM/DD/YY. 1 returns DD/MM/YY. 2 returns YY/MM/DD. 10 returns MM/DD/YYYY. 11 returns DD/MM/YYYY. 12 returns YYYY/MM/DD. An optional third parameter specifies the date separator character. If not specified, a slash (/) is used.
|
| DTOS | Converts a date to a character string using the format
YYYYMMDD.
|
| IIF | Returns one of two values, true or false. Parameters are a
logical expression, the true value, and the false value. If the logical expression
evaluates to true, the function returns the true value. Otherwise, it returns the
false value.
|
| STR | Converts a number to a character string. Parameters are
the number, the total number of output characters (including the decimal point), and
optionally the number of digits to the right of the decimal
point.
|
| STRVAL | Converts a value of any type to a character
string.
|
| TIME | Returns the time of day as a character
string.At 9:49 PM, TIME() returns 21:49:00. |
| TTOC |
Note: This function applies only to flat-file drivers that support SQL_TIMESTAMP: the
Btrieve driver and the dBASE (access to FoxPro 3.0) driver.
Converts a timestamp to a character string. An optional second parameter determines the format of the result: When set to 0 or none (the default), MM/DD/YY HH:MM:SS AM is returned. When set to 1, YYYYMMDDHHMMSS is returned, which is a suitable format for indexing.
|
| USERNAME | For Btrieve, the logon ID specified at connect time is returned. For all other flat-file drivers, an empty string is returned. |
| Function | Description |
|---|---|
| MOD | Divides two numbers and returns the remainder of the
division.
|
| LEN | Returns the length of a
string.
|
| MONTH | Returns the month part of a
date.
|
| DAY | Returns the day part of a
date.
|
| YEAR | Returns the year part of a
date.
|
| MAX | Returns the larger of two numbers.
|
| DAYOFWEEK | Returns the day of week (1-7) of a date
expression.
|
| MIN | Returns the smaller of two numbers.
|
| POW | Raises a number to a power.
|
| INT | Returns the integer part of a number . |
| ROUND | Rounds a number.
|
| NUMVAL | Converts a character string to a number. If the character string is
not a valid number, a zero (0) is returned.
|
| VAL | Converts a character string to a number. If the character string is
not a valid number, a zero (0) is returned.
|
| Function | Description |
|---|---|
| DATE | Returns today’s date. If today is 12/25/1999,
|
| TODAY | Returns today's date. If today is 12/25/1999,
|
| DATEVAL | Converts a character string to a
date.
|
| CTOD | Converts a character string to a date. An optional second parameter
specifies the format of the character string: 0 (the default) returns MM/DD/YY, 1 returns DD/MM/YY, and 2 returns YY/MM/DD.
|
The following examples use some of the number and date functions.
Retrieve all employees that have been with the company at least 90 days:
SELECT first_name, last_name FROM emp
WHERE DATE() – hire_date >= 90
Retrieve all employees hired in January of this year or last year:
SELECT first_name, last_name FROM emp
WHERE MONTH(hire_date) = 1
AND (YEAR(hire_date) = YEAR(DATE())
OR YEAR(hire_date) = YEAR(DATE()) – 1)