COUNTSTRING
Updated: 30 April 2009
Use COUNTSTRING to count the number of times a particular text occurs in another text.
Syntax
SELECT [wctString].[wct].[COUNTSTRING] (
<@Text, nvarchar(max),>
,<@SearchValue, nvarchar(max),>
,<@CaseSensitive, bit,>)
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.
@Value
is the value to search for in @Text. The @Value 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.
Return Types
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
-----------
6
(1 row(s) affected)
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
-----------
3
(1 row(s) affected)