Wednesday, 1 February 2017

MSSQL - Count number of occourance of a certain character in string


Watch on YouTube

Here i am counting number of "," (commas) in string

Declare @string varchar(1000)
Set @string = 'a, b, c, d'

Select len(@string) - len(replace(@string, ',', ''))

Here I am counting number of "a" in string

Declare @string varchar(1000)
Set @string = 'a, b, c, d'

Select len(@string) - len(replace(@string, 'a', ''))

No comments:

Post a Comment