Logo

COUNTSTRING

Updated 2023-11-10 19:26:53.947000

Syntax

SELECT [westclintech].[wct].[COUNTSTRING] (
  <@Text, nvarchar(max),>
 ,<@SearchValue, nvarchar(max),>
 ,<@CaseSensitive, bit,>)

Description

Use the scalar function COUNTSTRING to count the number of times a particular text occurs in another text.

Arguments

@Text

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

@CaseSensitive

declares the search as being either case sensitive or case insensitive, regardless of collation. The @CaseSenstive argument must be of data types that are implicitly convertible to bit.

@SearchValue

is the value to search for in @Text. The @Value argument can be of data types that are implicitly convertible to nvarchar or ntext.

Return Type

int

Remarks

COUNTSTRING does not support the use of wildcards.

COUNTSTRING supports case sensitive searches. @CaseSensitive = 1, makes the search case sensitive.

Examples

select wct.countstring(
'Finished files are the result of years of scientific study combined with the experience of years.'
,'f'
,0
);

This produces the following result.

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"6"}]}
select wct.countstring(
'Finished files are the result of years of scientific study combined with the experience of years.'
,'of '
,1
);

This produces the following result.

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