Skip to content

Instantly share code, notes, and snippets.

@beginor
Last active August 29, 2015 14:02
Show Gist options
  • Save beginor/c5de18d5560756ec5727 to your computer and use it in GitHub Desktop.
Save beginor/c5de18d5560756ec5727 to your computer and use it in GitHub Desktop.
Sql Server Cursor Sample
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