Could you try to find ways, thanks for your time.
You extracted data from the cursor, but did not click on the variables skipped in the WHILE loop, please see the code below, thanks.
drop table #temp select * into #temp from Employee; declare @eid as int; declare @nid as varchar(15); DECLARE Employee_Cursor CURSOR FOR SELECT A.EmployeeID, A.NationalIDNumber FROM #temp AS A OPEN Employee_Cursor; FETCH NEXT FROM Employee_Cursor INTO @eid , @nid ; WHILE @@FETCH_STATUS = 0 BEGIN IF (@eid > 10) BEGIN delete from #temp where #temp.EmployeeID = @eid; END FETCH NEXT FROM Employee_Cursor INTO @eid , @nid ; END; CLOSE Employee_Cursor; DEALLOCATE Employee_Cursor; GO select * from #temp
Update: I made changes to the 2nd FETCH statement, just added the highlighted part below, thanks
FETCH NEXT FROM Employee_Cursor INTO @eid, @nid ;
source share