This portal is to share my acquired knowledge related to Sql Server. I hope will be helpful for novice and professionals.

Monday, September 5, 2011

Count String Occurrence SQL Server

Sometime we have to count the occurrence of any specific string like :

Declare @Input NVarchar(Max)
Set @Input = 'A92GPGCatherineGeorgeB2VZ9VCARMENNAVARROARAUZ'

Here we have to count the occurrence.
so we can get this by using simple script :

Select (LEN(@Input) - LEN(REPLACE(@Input, '', ''))) / LEN('')

Thanks...

No comments: