SQL String Functions

The SQL Server provides various String Functions. These functions allow us to alter the individual characters in a string, compare two, search for a substring, extract substrings, and copy. You can also use these String Functions to convert them to lowercase or uppercase.

A string is a group of charters stored in Varchar or Nvarchar data type, which is useful to store names, product descriptions, etc. The SQL functions enable you to manipulate the string data by searching for the given substring and replacing it or adding so on. This article shows you the available list of string functions and their definitions.

SQL String Functions

The following table will show you the list of available String Functions. Use those links to see the practical example for each one of the string functions.

FunctionsDescription
ASCIIIt returns the ASCII code of the leftmost character of a character expression.
CHARConvert the integer value (ASCII code) to a character
CHARINDEXIt returns the index position of a specified expression
CONCATCombine or concatenate two or more and return the string.
CONCAT_WSThis function concatenates two or more SQL Server words using a separator.
DIFFERENCEReturn the difference between the SOUNDEX values of the specified character expressions
FORMATFormat the expression with the specified format.
LENTo find the length of a specified expression
LEFTReturns the leftmost characters from the specified expression
LTRIMIt removes the empty spaces from the Left side of a character’s expression
LOWERIt converts the given text or expression to Lowercase.
NCHARIt returns the Unicode character at the specified integer value
QUOTENAMEIt returns the Unicode with the delimiters
REPLACEWe can use this SQL Server function to replace the existing string with a new value.
REPLICATERepeat the existing sentence a given number of times.
REVERSEIt helps to reverse the specified expression
RIGHTReturn the rightmost characters from a given expression
RTRIMIt removes empty spaces from the Right-hand side of a given expression.
PATINDEXIt is used to return the starting index position of the first occurrence of a pattern in an expression.
SOUNDEXThis SQL String function returns the SOUNDEX code.
SPACEReturns the string of repeated spaces.
STRIt returns the string representation of the numeric expression.
STRING_ESCAPEIt escapes the special characters from the text.
STRING_SPLITSplit the character expression using the separator.
STRING_AGGIt concatenates the string expressions and places a specified separator in between them.
STUFFInsert one string inside another string
SUBSTRINGIt returns a specified number of characters from the given expression.
TRANSLATEIt translates the string expression by replacing the specified characters with a new set of characters.
TRIMRemove the empty spaces from both the right and left sides.
UNICODEReturn the Unicode (integer) value, as defined in Unicode standards.
UPPER This function converts the given text or expression to Uppercase.

Comments are closed.