As an example:
Please write me a cursor to iterate over this table with all necessary variables declared:
CREATE TABLE #TempContactIDs
(
ContactID INT
);
This saves SO much time for menial, repetitive cursor creation. That query will result in the following:
DECLARE @CurrentContactID INT;
DECLARE ContactCursor CURSOR FOR
SELECT ContactID FROM #TempContactIDs;
OPEN ContactCursor;
FETCH NEXT FROM ContactCursor INTO @CurrentContactID;
WHILE @@FETCH_STATUS = 0
BEGIN
-- Here is where you can use @CurrentContactID to do whatever you need.
-- This example just prints it.
PRINT @CurrentContactID;
FETCH NEXT FROM ContactCursor INTO @CurrentContactID;
END;
CLOSE ContactCursor;
DEALLOCATE ContactCursor;
0 Comments