Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created July 8, 2015 15:21
Show Gist options
  • Save jbnv/fb13ab2396c559ced87f to your computer and use it in GitHub Desktop.
Save jbnv/fb13ab2396c559ced87f to your computer and use it in GitHub Desktop.
SQL Server Query Cursor Pattern
DECLARE @tblName sysname
DECLARE @tblId INT
DECLARE @sql VARCHAR(MAX)
DECLARE cTable CURSOR FOR
SELECT [sql]
OPEN cTable
FETCH NEXT FROM cTable
INTO @sql
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @sql
FETCH NEXT FROM cTable INTO @tblName,@tblID
END
CLOSE cTable
DEALLOCATE cTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment