SQL Advanced Functions
Nov 4 · 3 min read
- CAST() Function:
- It is the Conversions Function used to convert data from one data type to another.
Syntax:
CAST(expression AS datatype(length))
Description:
- Expression - It is required for convert value.
- Datatype - It is required to convert expression to specific datatype.
- (Length) - It is optional. The length of the resulting data type.
Example:

1) CAST function convert the CustScore column from type Float to Integer.

2)CAST function convert the CustScore column from type Float to Decimal.

3)CAST function convert the CustDOB column from type Date to DateTime.

2. COALESCE() function:
- This function returns the first non-null value from the argument list.
- If all expressions evaluate to null, then the COALESCE function will return null.
- This function does not limit the number of arguments, but they must all of the same data type.
Syntax:
COALESCE(expression 1, … expression n)
Description:
- expression 1 to expression_n - Expressions is required to test non-null values.
Example:

- We use CustomerInfo table.


3. CONVERT() Function:
- It is the Conversions Function used to convert data from one data type to another.
- If the conversion fails, the function return an error.
Syntax:
CONVERT(data_type(length), expression, style)
Description:
- Datatype - It is required to convert expression to specific datatype.
- (Length) - It is optional. The length of the resulting data type.
- Expression - It is required for convert value.
- Style - It is an optional integer.
It determines how the convert() function will translate expression.
If style is NULL, the Convert() function will return NULL.
Example:


If you are new to SQL refer Below video for better Understanding.
