SQL Server Functions

SQL Server Functions : SQL Server functions has many built-in functions. This reference contains the string, numeric, date, conversion, and advanced functions in SQL Server.

SQL Server String Functions

Function Description
ASCII Returns the number code that represents the specific character
CHAR Returns the ASCII character based on the number code
CHARINDEX Returns the location of a substring in a string
CONCAT Concatenates two or more strings together
Concat with + Concatenates two or more strings together
DATALENGTH Returns the length of an expression (in bytes)
LEFT Extracts a substring from a string (starting from left)
LEN Returns the length of the specified string
LOWER Converts a string to lower-case
LTRIM Removes leading spaces from a string
NCHAR Returns the Unicode character based on the number code
PATINDEX Returns the location of a pattern in a string
REPLACE Replaces a sequence of characters in a string with another set of characters
RIGHT Extracts a substring from a string (starting from right)
RTRIM Removes trailing spaces from a string
SPACE Returns a string with a specified number of spaces
STR Returns a string representation of a number
STUFF Deletes a sequence of characters from a string and then inserts another sequence of characters into the string, starting at a specified position
SUBSTRING Extracts a substring from a string
UPPER Converts a string to upper-case

 

SQL Server Numeric Functions

Function Description
ABS Returns the absolute value of a number
AVG Returns the average value of an expression
CEILING Returns the smallest integer value that is greater than or equal to a number
COUNT Returns the count of an expression
FLOOR Returns the largest integer value that is equal to or less than a number
MAX Returns the maximum value of an expression
MIN Returns the minimum value of an expression
RAND Returns a random number or a random number within a range
ROUND Returns a number rounded to a certain number of decimal places
SIGN Returns a value indicating the sign of a number
SUM Returns the summed value of an expression

 

SQL Server Date Functions

Function Description
CURRENT_TIMESTAMP Returns the current date and time
DATEADD Returns a date after a certain time/date interval has been added
DATEDIFF Returns the difference between two date values, based on the interval specified
DATENAME Returns a specified part of a given date, as a string value
DATEPART Returns a specified part of a given date, as an integer value
DAY Returns the day of the month (from 1 to 31) for a given date
GETDATE Returns the current date and time
GETUTCDATE Returns the current UTC date and time
MONTH Returns the month (from 1 to 12) for a given date
YEAR Returns the year (as a four-digit number) for a given date

 

SQL Server Conversion Functions

Function Description
CAST Converts an expression from one data type to another
CONVERT Converts an expression from one data type to another

 

SQL Server Advanced Functions

Function Description
COALESCE Returns the first non-null expression in a list
CURRENT_USER Returns the name of the current user in the SQL Server database
ISDATE Returns 1 if the expression is a valid date, otherwise 0
ISNULL Lets you return an alternative value when an expression is NULL
ISNUMERIC Returns 1 if the expression is a valid number, otherwise 0
NULLIF Compares two expressions
SESSION_USER Returns the user name of the current session in the SQL Server database
SESSIONPROPERTY Returns the setting for a specified option of a session
SYSTEM_USER Returns the login name information for the current user in the SQL Server database
USER_NAME Returns the user name in the SQL Server database