THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server Functions


SQL Server has many built-in functions.


SQL Server String Functions

Function Description
ASCII Returns the number code that represents the specific character
CHAR Returns the 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 the specified number
COUNT Returns the count of an expression
FLOOR Returns the largest integer value that is equal to or less than the specified 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 which 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 value
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 value
YEAR Returns a four-digit year (as a number) for a given date value