Jeff Moden (7/5/2010)
... In the meantime, here's a simple cursor that reads a couple of values from a table and displays them. If you're in the GRID mode, it will end with an error. I've commented the code so you can see what each piece does.
USE AdventureWorks;
GO
--===== Declare some cursor related variables
DECLARE @EmployeeID INT,
@Title NVARCHAR(50)
--===== Declare the cursor using a SELECT
DECLARE Employee_Cursor CURSOR LOCAL FORWARD_ONLY READ_ONLY
FOR
SELECT EmployeeID, Title
FROM HumanResources.Employee;
--===== Open the cursor to begin using it.
-- This is where a static cursor gets loaded
-- into a temp table
OPEN Employee_Cursor;
--===== Start an infinite loop. We'll break out later...
WHILE 1 = 1
BEGIN
why not
WHILE (@@FETCH_STATUS = 0)