Search

Showing posts with label How many times a character (string) is repeated within a string. Show all posts
Showing posts with label How many times a character (string) is repeated within a string. Show all posts

Friday, July 13, 2012

How many times a character (string) is repeated within a string

Use below procedure to find the occurrence of some characters within a string.


DECLARE @strColumn VARCHAR(20)
DECLARE @searchString  VARCHAR(10)
DECLARE @intLen INT


SET @strColumn = '123asd123asd123' 
SET @searchString ='123'
SET @intLen = LEN(@searchString)


SELECT (LEN(@strColumn) - LEN(REPLACE(@strColumn, @searchString, '')))/@intLen