[Friday, August 13, 2010]
A few notes: First, I've only used this on SQL Server 2005. Also, the "insensitive" keyword on my cursor declaration tells it to ignore changes to the underlying table that might happen while I'm using the cursor. There are a bunch of other cursor types too so it's best to look them up and choose the right one.
DECLARE @itemID INT, @itemName VARCHAR(25)
DECLARE csrItems INSENSITIVE CURSOR FOR
SELECT * FROM tblItems
--Open the cursor
OPEN csrItems
FETCH FROM csrItems INTO @itemID, @itemName
--Start looping through the venues
WHILE @@FETCH_STATUS = 0
BEGIN
--Do stuff here...
FETCH NEXT FROM csrItems INTO @itemID, @itemName
END
CLOSE csrItems
DEALLOCATE csrItems
Posted by: Benjamin Felt
