

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

abhishekPosted Oct 23, 2024, 12:53 PM
Hi, here the word 'In' I am searching in sting 'hi i am in office right now will catchup sometime in the evening!' these formula giving 6 but actually it should give 3. So I thinking that these formula change will work SELECT (DATALENGTH(@string)-DATALENGTH(REPLACE(@string,@tosearch,'')))/DATALENGTH(@tosearch)/2 AS OccurrenceCount.