Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:


SQL
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


SQL
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:


SQL
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
Posted

1 solution

Why not:

SELECT engtitle , COUNT(*) FROM table GROUP BY engtitle
 
Share this answer
 
Comments
Vaibhav0078 14-Jun-14 0:30am    
But i have a like condition from which every variable has to pass on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900