SQL String Functions

In SQL Server, string functions perform character and string manipulations.

Arguments that are not string values, are implicitly converted to a text data type.



This function concatenates, or combines, first and last names.

SELECT CONCAT(FirstName, ' ', LastName) AS Name, 
       City, Country
  FROM Customer
Result:  91 records
Name City Country
Maria Anders Berlin Germany
Ana Trujillo México D.F. Mexico
Antonio Moreno México D.F. Mexico
Thomas Hardy London UK
Christina Berglund Luleå Sweden

String Functions

These are the built-in string functions in SQL Server.
Click on a function for more details.

Function Description
ASCII Returns the ASCII code value of a character
CHAR Returns the single-byte character with the specified integer code
CHARINDEX Returns the starting position of a string inside another string
CONCAT Combines two or more string value into a single (concatenated) string
DATALENGTH Rreturns the number of bytes used by an expression
DIFFERENCE Returns a value measuring the SOUNDEX difference between two strings
FORMAT Returns a value formatted with the specified format and optional culture
LEFT Returns the left part of a string with the given number of characters
LEN Returns the number of characters of a given string
LOWER Converts a string to lowercase
LTRIM Returns a string after it removes leading blanks
NCHAR Returns the Unicode character with the specified integer code
PATINDEX Returns the starting position of a pattern in a given string
QUOTENAME Returns a valid SQL Server delimited string as identifier.
REPLACE Replaces all occurrences of a string value with another string value
REPLICATE Repeats a string value a specified number of times.
REVERSE Returns a string with its characters reversed
RIGHT Returns the right part of a string with the specified number of characters
RTRIM Returns a string after it removes trailing blanks
SOUNDEX Returns a 4-character code to evaluate the sound similarity of two strings
SPACE Returns a string of repeated spaces
STR Returns character data converted from numeric data
STUFF Inserts a string into another string
SUBSTRING Returns part of a string or binary expression.
TRIM Removes spaces or other characters from start and end of a string.
UNICODE Returns the integer value for a Unicode character
UPPER Converts a string to uppercase.

You may also like


vsn 3.1