TRANSLATE (Transact‑SQL)
Syntax
TRANSLATE ( string_expression , characters , translations )
string_expression – The input string to be translated. nvarchar, varchar, char, or nchar types are allowed.
characters – A string containing the characters to be replaced.
translations – A string containing the replacement characters. Each character in characters is replaced by the character at the same position in translations.
Parameters
| Parameter | Type | Description |
|---|---|---|
| string_expression | nvarchar | varchar | char | nchar | The source string to translate. |
| characters | nvarchar | varchar | char | nchar | Characters to be replaced. |
| translations | nvarchar | varchar | char | nchar | Replacement characters. |
Return Type
Returns the same data type as string_expression with the translations applied. If string_expression is NULL, the result is NULL.
Remarks
- Translation is performed character by character. If a character in
charactersdoes not have a corresponding character intranslations, it is removed from the result. - Both
charactersandtranslationsmust be of the same length; otherwise, extra characters are ignored. - Use
TRANSLATEfor simple character mapping; for more complex pattern replacement, useREPLACEorREGEXP_REPLACE(SQL Server 2022+).
Examples
Basic character replacement
SELECT TRANSLATE('SQL Server 2022', 'S2022', 'R1111') AS Result;
-- Result: RQL Server 1111
Removing characters
SELECT TRANSLATE('Hello, World!', '!,', '') AS Cleaned;
-- Cleaned: Hello World
Case conversion
SELECT TRANSLATE('MixedCASE', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') AS Uppered;
-- Uppered: MIXEDCASE