T-SQL Functions

String Functions

LEN

Returns the number of characters of the specified string.

LEN(string_expression)

LEFT

Returns the left part of a string with the specified number of characters.

LEFT(string_expression, number_of_characters)

RIGHT

Returns the right part of a string with the specified number of characters.

RIGHT(string_expression, number_of_characters)

SUBSTRING

Extracts a part of a string.

SUBSTRING(string_expression, start_position, length)

REPLACE

Replaces all occurrences of a substring with another substring.

REPLACE(string_expression, string_to_replace, replacement_string)

UPPER

Converts a string to uppercase.

UPPER(string_expression)

LOWER

Converts a string to lowercase.

LOWER(string_expression)

TRIM

Removes leading, trailing, or both spaces from a string.

TRIM(string_expression)

Numeric Functions

ABS

Returns the absolute value of a number.

ABS(numeric_expression)

CEILING

Returns the smallest integer greater than or equal to a number.

CEILING(numeric_expression)

FLOOR

Returns the largest integer less than or equal to a number.

FLOOR(numeric_expression)

ROUND

Rounds a numeric expression to a specified length or precision.

ROUND(numeric_expression, length[, function])

SQRT

Returns the square root of a number.

SQRT(numeric_expression)

RAND

Returns a random float number between 0 and 1.

RAND([seed])

Date and Time Functions

GETDATE

Returns the current database system timestamp.

GETDATE()

DATEPART

Returns an integer representing the specified part of a date.

DATEPART(datepart, date)

DATENAME

Returns a character string representing the specified part of a date.

DATENAME(datepart, date)

DATEDIFF

Returns the difference between two dates.

DATEDIFF(datepart, startdate, enddate)

DATEADD

Adds a specified time interval to a date.

DATEADD(datepart, number, date)

Aggregate Functions

COUNT

Counts the number of rows.

COUNT(expression)

SUM

Calculates the sum of values.

SUM(expression)

AVG

Calculates the average of values.

AVG(expression)

MIN

Finds the minimum value.

MIN(expression)

MAX

Finds the maximum value.

MAX(expression)

System Functions

DB_NAME

Returns the name of the specified database.

DB_NAME([database_id])

USER_NAME

Returns the user name associated with a user ID.

USER_NAME([user_id])

SCHEMA_NAME

Returns the schema name for a schema ID.

SCHEMA_NAME([schema_id])