SQL Server REPLACE() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server REPLACE() Function

❮ SQL Server Functions

Example

Replace a sequence of characters in a string with another set of characters:

SELECT REPLACE('SQL Tutorial', 'T', 'M');
Try it Yourself »

Definition and Usage

The REPLACE() function replaces a sequence of characters in a string with another set of characters (not case-sensitive).

Tip: See also the STUFF() function.

Syntax

REPLACE(string1, string_to_replace, replacement_string)

Parameter Values

Parameter Description
string1 Required. The source string
string_to_replace Required. The string to search for in string1
replacement_string Required. The replacement string. All occurrences of string_to_replace will be replaced with replacement_string in string1

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

More Examples

Example

Replace a sequence of characters in a string with another set of characters:

SELECT REPLACE('SQL Tutorial', 'SQL', 'HTML');
Try it Yourself »

Example

Replace a sequence of characters in a string with another set of characters:

SELECT REPLACE('ABC ABC ABC', 'a', 'c');
Try it Yourself »

❮ SQL Server Functions