Created
March 9, 2012 12:14
-
-
Save Sebfh/2006275 to your computer and use it in GitHub Desktop.
SQL: Cursor
This file contains 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 @message nvarchar(250) | |
DECLARE #cursor_name# CURSOR FOR | |
#select_statement# | |
OPEN #cursor_name#; | |
FETCH NEXT FROM #cursor_name# | |
INTO @#variable#; | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
select @message = '#execute_statement#' | |
execute sp_executesql @message; | |
FETCH NEXT FROM #cursor_name# | |
INTO @#variable#; | |
END | |
CLOSE #cursor_name#; | |
DEALLOCATE #cursor_name#; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment