Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Replaces all occurrences of a specified string value with another string value.
Transact-SQL Syntax Conventions
REPLACE ( string_expression1 , string_expression2 , string_expression3 )
Returns nvarchar if one of the input arguments is of the nvarchar data type; otherwise, REPLACE returns varchar.
Returns NULL if any one of the arguments is NULL.
REPLACE performs comparisons based on the collation of the input. To perform a comparison in a specified collation, you can use COLLATE to apply an explicit collation to the input.
The following 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)
The following example uses the COLLATE
function.
SELECT REPLACE('Das ist ein Test' COLLATE Latin1_General_BIN,
'Test', 'desk' );
GO
Here is the result set.
------------
Das ist ein desk
(1 row(s) affected)
Please sign in to use this experience.
Sign in