Logo

SUBSTITUTE

Updated 2023-11-10 16:12:54.883000

Syntax

SELECT [westclintech].[wct].[SUBSTITUTE] (
  <@Text, nvarchar(max),>
 ,<@Old_text, nvarchar(max),>
 ,<@New_text, nvarchar(max),>
 ,<@Instance_num, int,>)

Description

Use the scalar function SUBSTITUTE to substitute new_text for old_text in a text string.

Arguments

@Instance_num

specifies which occurrence of @Old_text you want to replace with @New_text. The @Instance_num argument can be of data types that are implicitly convertible to int.

@New_text

is the text value to be used in the substitution for @Old_text. The @New_text argument can be of data types that are implicitly convertible to nvarchar or ntext.

@Text

is the text value to be evaluated. The @Text argument can be of data types that are implicitly convertible to nvarchar or ntext.

@Old_text

is the text value to be removed. The @Old_text argument can be of data types that are implicitly convertible to nvarchar or ntext.

Return Type

nvarchar(max)

Remarks

If @Instance_num is NULL, then all instances of @Old_text are replaced with @New_text.

Examples

select wct.substitute('April 19, 1919', '19', '20', 2);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"April 19, 2019"}]}
select wct.substitute('April 19, 1919', '19', '20', 1);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"April 20, 1919"}]}
select wct.substitute('April 19, 1919', '19', '20', NULL);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"April 20, 2020"}]}