REPLACE (T-SQL)

Replaces all occurrences of the second given string expression in the first string expression with a third expression.

Syntax

REPLACE('string_expression1', 'string_expression2', 'string_expression3')

Arguments
'string_expression1'
Is the string expression to search for string_expression2. string_expression1 can be of character or binary data.
'string_expression2'
Is the string expression for which to search in string_expression1 and to replace with string_expression3. string_expression2 can be of character or binary data.
'string_expression3'
Is the new string expression that replaces string_expression2 in string_expression1. string_expression3 can be of character or binary data.
Return Types

Returns character data if string_expression (1, 2, or 3) is one of the supported character data types. Returns binary data if string_expression (1, 2, or 3) is one of the supported binary data types.

Examples

This example replaces the string cde in abcdefghi with xxx.

SELECT REPLACE('abcdefghicde','cde','xxx')

GO

  

Here is the result set:

------------------------------------------------------------------------

abxxxfghixxx

(1 row(s) affected)

  

See Also
Data Types String Functions

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.