Question asked by a user of SQL & MSBI Groups-I have a paragraph, I have taken paragraph as a string in sql then I want how many words are repeated, and how many times the words are repeated?
Eg-“Ram name is Ram because of lord Ram since Ram Father is devoted to lord Ram.”
Output should be words_Repeated Word_Count as below
Solution-I have written the below code that will count each alphabet in the string.
declare @value varchar(100)
declare @index int
declare @String varchar(100)= 'Ram name is Ram because of lord Ram since Ram Father is devoted to lord Ram.'
declare @temp table(word_repeated varchar(100),Word_Count int)
set @index=charindex(' ',@string,1)
set @value=left(@string,charindex(' ',@string,1))
if exists(select * from @temp where word_repeated=@value)
update @temp set word_count=word_count+1 where word_repeated=@value
insert into @temp
Select @value, 1
select * from @temp
If you have any issue regarding SQL & BI where you are stuck write to me in the comment box I will try to help you out.