Friday, July 8, 2011

Create Simple T-SQL Cursor [example]

DECLARE curName CURSOR FOR SELECT     pk FROM tb_Table
      OPEN curName 
      
      FETCH NEXT FROM curName INTO @pk
      
      WHILE @@FETCH_STATUS = 0
      BEGIN
      
            --insert code here
            FETCH NEXT FROM curName INTO @pk --do not forget this line.. will cause an infinite loop
      END
      
CLOSE curName 
DEALLOCATE curName 



No comments:

Post a Comment