Conversion Functions

Conversion functions convert a value from one form to another.

Function Example Description

Cast

Cast(hiredate AS CHAR(40)) FROM employee

Changes the data type of an expression or a null literal to another data type. For example, you can cast a customer_name (a data type of Char or Varchar) or birthdate (a datetime literal).

Use Cast to change to a Date data type. Do not use ToDate.

IfNull

IfNull(Sales, 0)

Tests if an expression evaluates to a null value, and if it does, assigns the specified value to the expression.

IndexCol

SELECT IndexCol(VALUEOF (NQ_SESSION.GEOGRAPHY_LEVEL), Country, State, City), Revenue FROM Sales

Uses external information to return the appropriate column for the signed-in user to see.

NullIf

SELECT e.last_name, NULLIF(e.job_id, j.job_id) "Old Job ID" FROM employees e, job_history j WHERE e.employee_id = j.employee_id ORDER BY last_name, "Old Job ID";

Compares two expressions. If they are equal, then the function returns null. If they are not equal, then the function returns the first expression. You cannot specify the literal NULL for the first expression.

To_DateTime

SELECT To_DateTime ('2009-03-0301:01:00', 'yyyy-mm-dd hh:mi:ss') FROM sales

Converts string literals of dateTime format to a DateTime data type.