MSSQL String Functions

25 functions

CONCATCONCAT(str, ...)

Concatenates strings (NULLs treated as empty strings).

CONCAT_WSCONCAT_WS(sep, str, ...)

Concatenates strings with a separator between each.

SUBSTRINGSUBSTRING(str, start, len)

Extracts a substring from a specified position and length.

LEFTLEFT(str, n)

Returns the leftmost n characters.

RIGHTRIGHT(str, n)

Returns the rightmost n characters.

LENLEN(str)

Returns the character count (excluding trailing spaces).

DATALENGTHDATALENGTH(expr)

Returns the byte count of an expression.

UPPERUPPER(str)

Converts a string to uppercase.

LOWERLOWER(str)

Converts a string to lowercase.

LTRIMLTRIM(str)

Removes leading spaces.

RTRIMRTRIM(str)

Removes trailing spaces.

TRIMTRIM([chars FROM] str)

Removes leading and trailing spaces (or specified characters).

REPLACEREPLACE(str, from, to)

Replaces all occurrences of a substring.

CHARINDEXCHARINDEX(substr, str [, start])

Returns the position of a substring.

PATINDEXPATINDEX('%pattern%', str)

Returns the position of the first occurrence of a pattern.

REPLICATEREPLICATE(str, n)

Repeats a string n times.

REVERSEREVERSE(str)

Reverses a string.

STUFFSTUFF(str, start, len, newstr)

Deletes a portion of a string and inserts a new string.

FORMATFORMAT(value, format [, culture])

Formats a value as a specified format string.

STRING_AGGSTRING_AGG(expr, sep) [WITHIN GROUP (ORDER BY ...)]

Aggregates strings with a separator.

STRING_SPLITSTRING_SPLIT(str, sep)

Splits a string by a separator and returns a row set.

QUOTENAMEQUOTENAME(str [, quote_char])

Adds brackets or quotes to an identifier.

TRANSLATETRANSLATE(str, from_chars, to_chars)

Performs character-by-character substitution.

ASCIIASCII(str)

Returns the ASCII code of the first character.

CHARCHAR(n)

Converts an ASCII code to a character.