Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

SQL Server - Count No of occurrence of a character or word in a string

Article:
Viewed:  519 
Posted On:  4/1/2016 7:28:17 PM 
How we can Count No of occurrence of a character or word in a string in SQL Server? 

 

In SQL Server how we can count no of occurrence of a character or word in a string.

1.png

Image 1.

2.png

Image 2.

DECLARE @string VARCHAR(MAX)='Noida, short for the New Okhla Industrial Development Authority,
is a planned city in India under the management of the
     New Okhla Industrial Development Authority.It is part of National Capital Region of India. '

DECLARE @tosearch VARCHAR(MAX)='In' 
SELECT (DATALENGTH(@string) - DATALENGTH(REPLACE(@string,@tosearch,''))) / DATALENGTH(@tosearch)
AS OccurrenceCount

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us