Returns the string provided as a first argument after some characters specified in the second argument are translated into a destination set of characters.
TRANSLATE ( inputString, characters, translations)
inputString
Is an expression of any character type (nvarchar, varchar, nchar, char).
characters
Is a expression of any character type containing characters that should be replaced.
translations
Is a character expression that matches second argument by type and length.
Returns a character expression of the same type as inputString where characters from the second argument are replaced with the matching characters from third argument.
TRANSLATE function will return an error if characters and translations have different lengths. TRANSLATE function should return unchanged input if null vales are provided as characters or replacement arguments. The behavior of the TRANSLATE function should be identical to the REPLACE function.
The behavior of the TRANSLATE function is equivalent to using multiple REPLACE functions.
TRANSLATE is always SC collation aware.
The following query replaces square and curly braces in the input string with parentheses:
SELECT TRANSLATE('2*[3+4]/{7-2}', '[]{}', '()()');
Here is the result set.
2*(3+4)/(7-2)
[!NOTE] The
TRANSLATEfunction in this example is equivalent to but much simplier than the following statement usingREPLACE:SELECT REPLACE(REPLACE(REPLACE(REPLACE('2*[3+4]/{7-2}','[','('), ']', ')'), '{', '('), '}', ')');
GeoJSON is a format for encoding a variety of geographic data structures. With the TRANSLATE function, developers can easily convert GeoJSON points to WKT format and vice versa. The following query replaces square and curly braces in input with regular braces:
SELECT TRANSLATE('[137.4, 72.3]' , '[,]', '( )') AS Point,
TRANSLATE('(137.4 72.3)' , '( )', '[,]') AS Coordinates;Here is the result set.
| Point | Coordinates |
|---|---|
| (137.4 72.3) | [137.4,72.3] |
CONCAT (Transact-SQL)
CONCAT_WS (Transact-SQL)
FORMATMESSAGE (Transact-SQL)
QUOTENAME (Transact-SQL)
REPLACE (Transact-SQL)
REVERSE (Transact-SQL)
STRING_AGG (Transact-SQL)
STRING_ESCAPE (Transact-SQL)
STUFF (Transact-SQL)
String Functions (Transact-SQL)