Last active
August 29, 2015 14:02
-
-
Save beginor/c5de18d5560756ec5727 to your computer and use it in GitHub Desktop.
Sql Server Cursor Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use Northwind | |
Go | |
Declare @CatId Int, @CatName NvarChar(50) | |
Declare catCur Cursor For | |
Select c.CategoryId, c.CategoryName From Categories c | |
Open catCur | |
Fetch Next From catCur InTo @CatId, @CatName | |
While (@@FETCH_STATUS = 0) | |
Begin | |
-- do some thing | |
Print @CatId | |
Print @CatName | |
Fetch Next From catCur InTo @CatId, @CatName | |
End | |
Close catCur | |
Deallocate catCur |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment