I have Engtitle field in sql server table with millions of words.
I want to check how many times each word of table repeats within the table with following condition:
select distinct engtitle from table
where a1 = 'EHD'
I will get 2million records with above query.and i want to check each word from above query in within same table..with this condition:
Suppose @variable is a one word i get from above query
select COUNT(*) from table
where engtitle like '%@variable %'
and I want to insert each word with their counts in a table..table2(engtitle,count)
For above condition I tried following cursor:
declare @Engword varchar(max)
DECLARE word_cursor CURSOR FOR
select distinct engtitle from table
where a1 = 'EHD'
ORDER BY Engtitle;
OPEN Word_cursor;
FETCH NEXT FROM Word_cursor
INTO @Engword;
Print @Engword + 'f'
WHILE (select COUNT(*) from table where engtitle like '%@Engword %') > 0 and @@FETCH_STATUS = 0
BEGIN
Print @Engword + 's'
Insert into Table1(Engtitle,[count])
Values(@Engword,(select COUNT(*) from table
where engtitle like '%@Engword %'))
IF (select COUNT(*) from table
where engtitle like '%@Engword %' ) < 0
Begin
Insert into Table1(Engtitle,[count])
Values(@Engword,(select COUNT(*) from table
where engtitle like '%@Engword %'))
END
FETCH NEXT FROM Word_cursor
INTO @Engword;
END
CLOSE Word_cursor;
DEALLOCATE Word_cursor;
GO