If you wanna find count of particular character in a string, you can use the following SQL code:
For example: if you wanna find how many 'l' in the word 'sqldeveloper', you can create proc with above code and run the proc as mentioned below.
create proc charcount @a varchar(8000),@b varchar(8000) as declare @i int = 1, @count int =0, @j int=0 select @j=LEN(@b) while @i<=LEN(@a) begin if (select substring(@a,@i,@j))=@b begin set @count=@count+1 end set @i=@i+1 end select @count go
EXEC charcount 'sqldeveloper','l' ---- give the inputs @a, @b
You can also find count of word in the sentence. For example:
create proc charcount @a varchar(8000),@b varchar(8000) as declare @i int = 1, @count int =0, @j int=0 select @j=LEN(@b) while @i<=LEN(@a) begin if (select substring(@a,@i,@j))=@b begin set @count=@count+1 end set @i=@i+1 end select @count go
EXEC charcount 'SQL DEVELOPERS ARE ONE OF THE BEST DEVELOPERS IN THE WORLD', 'DEVELOPERS'
You can also find count of word in the sentence. For example:
create proc charcount @a varchar(8000),@b varchar(8000) as declare @i int = 1, @count int =0, @j int=0 select @j=LEN(@b) while @i<=LEN(@a) begin if (select substring(@a,@i,@j))=@b begin set @count=@count+1 end set @i=@i+1 end select @count go
EXEC charcount 'SQL DEVELOPERS ARE ONE OF THE BEST DEVELOPERS IN THE WORLD', 'DEVELOPERS'
declare @a varchar(max), @b varchar(max)
set @a = 'SQL DEVELOPERS ARE ONE OF THE BEST DEVELOPERS IN THE WORLD'
set @b = 'DEVELOPERS'
select (len(@a) - len(replace(@a,@b,''))) / len(@b)