REPLACE()
Transact-SQL reference for the REPLACE function, which replaces all occurrences of a specified string value with another string value.
Signature
REPLACE ( string_expression , string_pattern , string_replacement )Parameters
- string_expression — Is the string expression to be searched. *string_expression* can be of a character or binary data type.
- string\_pattern — Is the substring to be found. *string_pattern* can be of a character or binary data type. *string_pattern* must not exceed the maximum number of bytes that fits on a page. If *string_pattern* is an empty string (''), *string_expression* is returned unchanged.
- string\_replacement — Is the replacement string. *string_replacement* can be of a character or binary data type.
Examples
SELECT REPLACE('keyboard', 'board', 'stone') AS replaced;replaced
----------------------------------------------------------------
keystoneRun against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.
Available on
- SQL Server 2017 and later
- Azure SQL Database
- Azure SQL Managed Instance
- Azure Synapse Analytics
- Analytics Platform System (PDW)
- Microsoft Fabric warehouse
- Fabric SQL database
Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.