Preface: In the Transact-SQL language, functions are used to perform some special operations to support the standard commands of SQL Server. SQL Server contains a variety of different functions to accomplish various tasks, each function has a name, there is a pair of parentheses after the name, such as: GETDATE(). Most functions require one or more arguments in parentheses.
Article directory
1. Conversion function
2. String function
3. Date function
4. Mathematical function
5. System function
6. Other functions
Commonly used functions:
conversion function
Used to convert between data types
String functions
String used to control the return to the user
date function
for manipulating date values
math function
Used to perform algebraic operations on numbers
System function
Get system information about objects and settings in SQL Server
other functions
Other commonly used functions in SQL Server
1. Conversion functions
Function name Description Example
CAST Converts an expression of one data type to an expression of another data type SELECT CAST(12345 AS VARCHAR(5))
returns: String 12345
CONVERT Converts the expression of one data type The expression SELECT CONVERT(VARCHAR(5),12345) that is converted to another data type
returns: string 12345
2. String function
Function name Description Example
CHARINDEX Find the starting point of a specified string in another string Start position SELECT CHARINDEX('Server','SQL Server course',1)
returns: 5
DATALENGTH returns the number of bytes used to represent any expression SELECT DATALENGTH('SQL Server')
returns