bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

SQL Server REPLACE() Function

Concept visual

SQL Server REPLACE() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Replace "T" with "M":

SELECT REPLACE('SQL Tutorial', 'T', 'M');

Definition and Usage

The REPLACE() function replaces all occurrences of a substring within a string, with a new substring.

Note:

Formula

The search is case - insensitive.

Tip:

Also look at the STUFF() function.

Syntax

Replace(

string, old_string, new_string )

Parameter Values

Parameter

Description string

Required. The original string old_string Required. The string to be replaced new_string Required. The new replacement string

Technical Details

Works in:

SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse

More Examples

Example

Replace "SQL" with "HTML":

SELECT REPLACE('SQL Tutorial', 'SQL', 'HTML');

Example

Replace "a" with "c":

SELECT REPLACE('ABC ABC ABC', 'a', 'c');

Previous

❮ SQL Server Functions

Next

Previous

SQL Server QUOTENAME() Function

Next

SQL Server REPLICATE() Function