Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
SSIS Integration Runtime in Azure Data Factory
Returns a character expression after replacing a character string within the expression with either a different character string or an empty string.
Note
The REPLACE function frequently uses long strings. The consequences of truncation can be handled gracefully or cause a warning or an error. For more information, see Syntax (SSIS).
REPLACE(character_expression,searchstring,replacementstring)
character_expression
Is a valid character expression that the function searches.
searchstring
Is a valid character expression that the function attempts to locate.
replacementstring
Is a valid character expression that is the replacement expression.
DT_WSTR
The length of searchstring must not be zero.
The length of replacementstring may be zero.
The searchstring and replacementstring arguments can use variables and columns.
REPLACE works only with the DT_WSTR data type. character_expression1, character_expression2, and character_expression3 arguments that are string literals or data columns with the DT_STR data type are implicitly cast to the DT_WSTR data type before REPLACE performs its operation. Other data types must be explicitly cast to the DT_WSTR data type. For more information, see Cast (SSIS Expression).
REPLACE returns a null result if any argument is null.
This example uses a string literal. The return result is "All Terrain Bike".
REPLACE("Mountain Bike", "Mountain","All Terrain")
This example removes the string "Bike" from the Product column.
REPLACE(Product, "Bike","")
This example replaces values in the DaysToManufacture column. The column has an integer data type and the expression includes casting DaysToManufacture to the DT_WSTR data type.
REPLACE((DT_WSTR,8)DaysToManufacture,"6","5")
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today