You are on page 1of 1

declare @value varchar(100)

declare @index int


declare @String varchar(100)= 'h name is Ram because of lord Ram since Ram Fath
er is devoted to lord Ram.'
declare @temp table(word_repeated varchar(100),Word_Count int)
while (len(@string)>0)
begin
set @index=charindex(' ',@string,1)
if @index=0
begin
set @value=@string
break;
end
else
set @value=left(@string,charindex(' ',@string,1))
if exists(select * from @temp where word_repeated=@value)
begin
update @temp set word_count=word_count+1 where word_repeated=@v
alue
end
else
insert into @temp
Select @value, 1
set @String=Right(@string,Len(@string)-@index)
end
select * from @temp

You might also like