SQL Server - Cursor Syntax

by Administrator 1. February 2010 21:54

 -- Variables to hold the data


 DECLARE @Var1 int
 DECLARE @Var2 datetime

 -- CURSOR


 DECLARE db_cursor CURSOR FOR 
 SELECT  Col1,
Col2
 FROM Table1

 OPEN db_cursor  
 FETCH NEXT FROM db_cursor INTO @Var1 , @Var2

 WHILE @@FETCH_STATUS = 0  
 BEGIN   
  -- DO STUFF HERE

  
  FETCH NEXT FROM db_cursor INTO @Var1 , @Var2 
 END  

 CLOSE db_cursor  
 DEALLOCATE db_cursor

 

 

 

 

 


Buy Me a Beer ?

If you've found this site useful, you could help support its running costs by either checking out the adverts on the page if you find anything that interests you - or by making a small donation