REPLACE (SSIS Expressions)

Returns a character expression after replacing a character string within the expression with either a different character string or an empty string.


The REPLACE function frequently uses long strings, and therefore is more likely to incur the 4000-character limit on expression length. If the evaluation result of an expression has the Integration Services data type DT_WSTR or DT_STR, the expression will be truncated at 4000 characters. If the result type of a sub-expression is DT_STR or DT_WSTR, that sub-expression will likewise be truncated to 4000 characters, regardless of the overall expression result type. The consequences of truncation can be handled gracefully or cause a warning or an error. For more information, see Syntax (SSIS Expressions).



Is a valid character expression that the function searches.


Is a valid character expression that the function attempts to locate.


Is a valid character expression that is the replacement expression.

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 Expressions).

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.


Community Additions