Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Plz suggest me if there is any other option instead of cursor.. I have store procedure in which I use cursor but it takes long time to run on online server.. So if there is any other option that I can use in place of cursor plz tell me..
thanks in advance..
Posted
Comments
dimpledevani 6-Feb-14 1:47am    
It depends on your requirements.You can use while loop or try indexing your tables
heta.dave 8-Feb-14 0:44am    
thanks..
Dnyaneshwar Kondbale 6-Feb-14 1:54am    
Yes, Its depends on your requirement.. You can use while Loop as well as you can try TVP(Table Value Parameter) in SQL Server 2008.to Avoid looping must go with TVP.

Hi Heta,

Please find below example.


We can use Temporary tables instead of Cursors.


SQL
DECLARE @MaxCount INT
DECLARE @Count INT
SET @Count =1


SQL
CREATE TABLE  #TempTable
(  
Id INT  Identity(1,1),  
KeyWord VARCHAR(100)  
)  

SQL
SELECT @MaxCount =MAX(ID) FROM #TempTable



WHILE (@Count < = @MaxCount)
BEGIN



-- Do some operation 

SET @Count= @Count+1;


END
 
Share this answer
 
In past, I have answered similar question, check it out alternatives
Cursor alternatives[^]
 
Share this answer
 

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