Skip to content

Instantly share code, notes, and snippets.

@arijusg
Created June 24, 2014 13:04
Show Gist options
  • Save arijusg/e9d8d78ed4f2ecf4974e to your computer and use it in GitHub Desktop.
Save arijusg/e9d8d78ed4f2ecf4974e to your computer and use it in GitHub Desktop.
SQL Cursor usage
USE RedFoxAuto
DECLARE @PricelistID varchar(50), @lName varchar(50)
DECLARE cursorName CURSOR LOCAL SCROLL STATIC FOR
SELECT pricelistID, pricelistName FROM productPricelistNames
OPEN cursorName -- open the cursor
FETCH NEXT FROM cursorName INTO @PricelistID, @lName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @PricelistID + ' ' + @lName -- print the name
--SELECT @PricelistID, @lName
FETCH NEXT FROM cursorName INTO @PricelistID, @lName
END
CLOSE cursorName -- close the cursor
DEALLOCATE cursorName -- Deallocate the cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment