You can call a number of functions when you are building an expression, including:
In general, if you are familiar with the functions available in your database, you can use the function names and syntax supported by that database. In some cases, such as when you are creating views, stored procedures, or triggers, you must use database-specific function names and syntax.
If you are creating queries (not views, stored procedures, or triggers) that might be run against different databases, you can also use ODBC functions, which are supported by virtually all database drivers no matter what database you are querying. ODBC syntax includes the "fn" qualifier in front of the function name and braces around the entire function. For example, the following expression uses an ODBC function to convert text to lowercase letters:
{fn LCASE ( address ) }
The Query Designer can help you work with functions by:
For details about functions supported by the database, refer to the documentation for the database. For details about ODBC functions, refer to the Open Database Connectivity (ODBC) SDK in the Microsoft Developer Network or to the Microsoft ODBC 2.0 Programmer’s Reference and SDK Guide.
Note You can use a special set of functions, the aggregate functions such as SUM( ) and AVG( ), to create queries that summarize data. For details, see Summarizing and Grouping.
The following functions for manipulating character strings provide a sampling of those that are available in ODBC and in many databases, such as Microsoft SQL Server.
Function | Description | Example |
LCASE( )1, LOWER( ) |
Converts strings to lowercase |
|
LTRIM( ) | Removes leading spaces from a string |
|
SUBSTRING( ) | Extracts one or more characters from a string |
|
UCASE( )1, UPPER( ) |
Converts strings to uppercase |
|
1If calling as an ODBC function, use syntax such as: { fn LCASE(
text) }
.
The following functions (or others similar to them) are available in either ODBC or in databases such as Microsoft SQL Server and Microsoft Access.
Note Oracle uses the TO_DATE function to format dates. For details, see Query Designer Considerations for Oracle Databases.
Function | Description | Example |
DATEDIFF( ) | Calculates an interval between two dates. |
|
DATEPART( ) | Returns the specified portion of a date or datetime column, including the day, month, or year. |
|
CURDATE( )1, GETDATE( ) or DATE( ) |
Returns the current date in datetime format. This function is useful as input for many other date functions, such as calculating an interval forward or backward from today. |
|
1If calling as an ODBC function, use syntax such as: { fn CURDATE() }
.
ODBC and most databases provide some mathematical functions that you can use when performing calculations. The following functions are typical of those available in many databases, but you should refer to the ODBC documentation and documentation for the database for details about what functions are available and what arguments they take.
Note You can use the aggregate functions AVG( ), COUNT( ), MAX( ), MIN( ), and SUM( ) to create averages and totals in your report. For details, see Summarizing and Grouping.
Function | Description | Example |
ROUND( ) | Rounds a number off to the specified number of decimal places. |
|
FLOOR( ) | Rounds a number down to the nearest (smallest) whole number. |
|
CEILING( ) | Rounds a number up to the nearest whole number. |
|
ODBC and most databases make available special functions that you can use to return information about the current database, current user, or the server. The following functions are typical of those available in many databases, but refer to the ODBC documentation or documentation for the database for details about what functions are available and what arguments they take.
Function | Description | Example |
DATALENGTH( ) | Returns the number of bytes used by the specified expression. |
|
USER( )1, USER_NAME( ) |
Returns the current user name. |
|
1If calling as an ODBC function, use syntax such as: { fn USER() }
.
In addition to the functions listed earlier, ODBC and most databases provide other functions to help you create queries, such as data type conversion or other utility functions. The following functions illustrate the type of utility functions that are available in many databases.
Function | Description | Example |
CONVERT( ) | Converts data from one data type into another. Useful to format data or to use the contents of a data column as an argument in a function that requires a different data type. |
|
SOUNDEX( ) | Returns the Soundex code for the specified expression, which you can use to create "sounds like" searches. |
|
STR( ) | Converts numeric data into a character string so you can manipulate it with text operators. |
|