SQL Server String Functions

SQL Server provides a variety of string functions that allow you to manipulate and work with character or text data. Here are some commonly used SQL Server string functions:

FunctionDescription
ASCIIReturn the ASCII code value of a character
CHARConvert an ASCII value to a character
CHARINDEXSearch for a substring inside a string starting from a specified location and return the position of the substring.
CONCATJoin two or more strings into one string
CONCAT_WSConcatenate multiple strings with a separator into a single string
DIFFERENCECompare the SOUNDEX() values of two strings
FORMATReturn a value formatted with the specified format and optional culture
LEFTExtract a given a number of characters from a character string starting from the left
LENReturn a number of characters of a character string
LOWERConvert a string to lowercase
LTRIMReturn a new string from a specified string after removing all leading blanks
NCHARReturn the Unicode character with the specified integer code, as defined by the Unicode standard
PATINDEXReturns the starting position of the first occurrence of a pattern in a string
QUOTENAMEReturns a Unicode string with the delimiters added to make the input string a valid delimited identifier
REPLACEReplace all occurrences of a substring, within a string, with another substring
REPLICATEReturn a string repeated a specified number of times
REVERSEReturn the reverse order of a character string
RIGHTExtract a given a number of characters from a character string starting from the right
RTRIMReturn a new string from a specified string after removing all trailing blanks
SOUNDEXReturn a four-character (SOUNDEX) code of a string based on how it is spoken
SPACEReturns a string of repeated spaces
STRReturns character data converted from numeric data
STRING_AGGConcatenate rows of strings with a specified separator into a new string
STRING_ESCAPEEscapes special characters in a string and returns a new string with escaped characters
STRING_SPLITA table-valued function that splits a string into rows of substrings based on a specified separator
STUFFDelete a part of a string and then insert another substring into the string starting at a specified length
SUBSTRINGExtract a substring within a string starting from a specified location with a specified length
TRANSLATEReplace several single-characters, one-to-one translation in one operation.
TRIMReturn a new string from a specified string after removing all leading and trailing blanks
UNICODEReturns the integer value, as defined by the Unicode standard of a character
UPPERConvert a string to uppercase

These are just a few examples of the string functions available in SQL Server. Each function has specific syntax and usage requirements, which can be found in the SQL Server documentation for the corresponding version of the software.

Leave a Reply

Your email address will not be published. Required fields are marked *