T-SQL Functions
Aggregate Functions
AVG()
Returns the average value of an expression.
AVG( [ALL | DISTINCT] expression )
COUNT()
Counts the number of rows or non-null values.
COUNT( { [ALL | DISTINCT] expression } | * )
MAX()
Returns the maximum value of an expression.
MAX( expression )
MIN()
Returns the minimum value of an expression.
MIN( expression )
SUM()
Calculates the sum of values in an expression.
SUM( [ALL | DISTINCT] expression )
Scalar Functions
LEN() / DATALENGTH()
Returns the length of a string or the number of bytes.
LEN( string_expression )
DATALENGTH( string_expression )
GETDATE()
Returns the current database system date and time.
GETDATE()
ISNULL()
Replaces NULL with a specified replacement value.
ISNULL( check_expression , replacement_value )
CAST() / CONVERT()
Converts an expression from one data type to another.
CAST ( expression AS data_type )
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
SUBSTRING()
Returns a part of a character string.
SUBSTRING ( string_expression , start , length )
LEFT() / RIGHT()
Returns characters from the left or right side of a string.
LEFT ( character_expression , integer_expression )
RIGHT ( character_expression , integer_expression )
REPLACE()
Replaces all occurrences of a specified string with another string.
REPLACE ( string_expression , string_pattern , string_replacement )
System Functions
@@ROWCOUNT
Returns the number of rows affected by the last statement.
@@ROWCOUNT
DB_NAME()
Returns the name of the specified database.
DB_NAME ( [ database_id ] )
HOST_NAME()
Returns the workstation name.
HOST_NAME()