Tutorialsteacher

Follow Us

SQL Server Built-in Functions

The following is the list of built-in String functions, DateTime functions, Numeric functions and conversion functions.

String Functions

FunctionDescription
ASCIIReturns the ASCII code value for the leftmost character of a character expression.
CHARReturns a character for an ASCII value.
CHARINDEXSearches for one character expression within another character expression and returns the starting position of the first expression.
CONCATConcatenates two or more string values in an end to end manner and returns a single string.
LEFTReturns a given number of characters from a character string starting from the left
LENReturns a specified number of characters from a character string.
LOWERConverts a string to lower case.
LTRIMRemoves all the leading blanks from a character string.
NCHARReturns the Unicode character with the specified integer code, as defined by the Unicode standard.
PATINDEXReturns the starting position of the first occurrence of the pattern in a given string.
REPLACEReplaces all occurrences of a specified string with another string value.
RIGHTReturns the right part of a string with the specified number of characters.
RTRIMReturns a string after truncating all trailing spaces.
SPACEReturns a string of repeated spaces.
STRReturns character data converted from numeric data. The character data is right justified, with a specified length and decimal precision.
STUFFInserts a string into another string. It deletes a specified length of characters from the first string at the start position and then inserts the second string into the first string at the start position.
SUBSTRINGReturns part of a character, binary, text, or image expression
UPPERConverts a lowercase string to uppercase.

DateTime Functions

FunctionDescription
CURRENT_TIMESTAMPReturns the current system date and time of the computer on which the SQL server instance is installed. Time zone is not included.
DATEADDReturns a new datetime value by adding an interval to the specified datepart of the specified date
DATEDIFFReturns the difference in datepart between two given dates.
DATENAMEReturns a datepart as a character string.
DATEPARTReturns a datepart as an integer
DAYReturns the Day as an integer representing the Day part of a specified date.
GETDATEReturns a datetime value containing the date and time of the computer on which the SQL Server instance is installed. It does not include the time zone.
GETUTCDATEReturns a datetime value in UTC format (Coordinated Universal Time), containing the date and time of the computer on which the SQL Server instance is installed.
MONTHReturns the Month as an integer representing the Month part of a specified date.
YEARReturns the Year as an integer representing the Year part of a specified date.
ISDATEDetermines whether the input is a valid date, time or datetime value.

Numeric Functions

FunctionDescription
ABSReturns the absolute value of a number.
AVGReturns the average value of an expression/column values.
CEILINGReturns the nearest integer value which is larger than or equal to the specified decimal value.
COUNTReturns the number of records in the SELECT query.
FLOORReturns the largest integer value that is less than or equal to a number. The return value is of the same data type as the input parameter.
MAXReturns the maximum value in an expression.
MINReturns the minimum value in an expression.
RANDReturns a random floating point value using an optional seed value.
ROUNDReturns a numeric expression rounded to a specified number of places right of the decimal point.
SIGNReturns an indicator of the sign of the input integer expression.
SUMReturns the sum of all the values or only the distinct values, in the expression. NULL values are ignored.

Conversion Functions

FunctionDescription
CASTConverts a value of any type to a specified data type.
CONVERTConverts and formats a value of one data type to another data type.
TRY_CASTReturns a value cast to a specified data type if the cast succeeds else returns null.
TRY_CONVERTReturns a value cast to a specified data type if the cast succeeds else returns null.

Advanced Functions

FunctionDescription
IIFIt can be used as if-else condition in a query.
ISNULLReplaces the NULL value with a given replacement expression.
ISNUMERICDetermines whether the given expression is a valid numeric type or not.
USER_NAMEReturns the current logged-in user name.