Search

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 

2 comments:

  1. Piece of writing writing is also a excitement, if you be acquainted with then you can write otherwise it is complicated
    to write.
    My web site: ppc advertising networks

    ReplyDelete
  2. Nice! Exactly what I was looking for. Thanks.

    ReplyDelete