This SQL Tutorial provides you a summary of some of the most common Built-in Scalar Functions in SQL Server. For this lesson’s exercises, use this link.
SQL Server Scalar Functions allow you to perform different calculations on data values. These functions operate on single rows only and produce one result per row. There are different types of Scalar Functions, this tutorial covers the following:
- String functions – functions that perform operations on character values.
- Numeric functions – functions that perform operations on numeric values.
- Date functions – functions that perform operations on date values.
- Conversion functions – functions that convert column data types.
- NULL-related Functions – functions for handling null values.
Note: this tutorial focuses on SQL Server Scalar Functions; for more details about Group Functions, use the following link
SQL Server String Functions
|
Syntax |
Description |
Function |
|
Returns the right part of a character string with the specified number of characters. | |
|
Returns the left part of a character string with the specified number of characters. | |
|
Returns the number of characters of the specified string expression. | |
|
Returns a character string after truncating all trailing blanks. | |
|
Returns a character expression after it removes leading blanks. | |
|
Replaces all occurrences of a specified string value with another string value. | |
|
Returns the reverse order of a string value. | |
|
Returns part of a text. | |
|
Returns a character expression after converting uppercase character data to lowercase. | |
|
Returns a character expression with lowercase character data converted to uppercase. |
SQL Server Date Functions
| Syntax |
Description |
Function |
|
Returns a specified date with the specified number interval added to a specified datepart of that date. | |
|
Returns the count of the specified datepart boundaries crossed between the specified startdate and enddate. | |
|
Returns an integer representing the day (day of the month) of the specified date. | |
|
Returns an integer that represents the month of the specified date. | |
|
Returns an integer that represents the year of the specified date. | |
|
Returns the current database system date. This value is derived from the operating system of the computer on which the instance of SQL Server is running. |
SQL Server Numeric Functions
|
Syntax |
Description |
Function |
|
Returns the largest integer less than or equal to the specified numeric expression. | |
|
Returns the smallest integer greater than, or equal to, the specified numeric expression. | |
|
Returns a numeric value, rounded to the specified length or precision. |
SQL Server Conversion Functions
|
Syntax |
Description |
Function |
|
Converts an expression of one data type to another |
|
|
Converts an expression of one data type to another |
SQL Server NULL-Related Functions
|
Syntax |
Description |
Function |
|
Replaces NULL with the specified replacement value. |