Created
October 3, 2017 14:14
-
-
Save kenny-evitt/d60d501f60a36e5ca29f98be99634848 to your computer and use it in GitHub Desktop.
T-SQL cursor template
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
DECLARE @columnValue int; | |
DECLARE cursor_ CURSOR LOCAL | |
FORWARD_ONLY | |
FAST_FORWARD | |
READ_ONLY | |
FOR | |
SELECT Column | |
FROM dbo.Table; | |
OPEN cursor_; | |
FETCH cursor_ INTO @columnValue; | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
-- Do something with `@columnValue` | |
FETCH cursor_ INTO @columnValue; | |
END | |
CLOSE cursor_; | |
DEALLOCATE cursor_; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment