title: How i can use cursor to delete record from table
body: <p>I want to use cursor to delete record from table. How can I do it?</p>
  
  <p>I use MSSQL 2008 Express this code does not delete anything from #temp. I also tried where current of cursor_name did not work.</p>
  
  <p>Here is my sample code:</p>
  
  <pre><code>use AdventureWorks
  
  drop table #temp
  select * into #temp from HumanResources.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 &gt; 10)
        BEGIN
          delete from #temp where #temp.EmployeeID = @eid;
        END
        FETCH NEXT FROM Employee_Cursor;
     END;
  CLOSE Employee_Cursor;
  DEALLOCATE Employee_Cursor;
  GO
  
  select * from #temp
  </code></pre>
  
  <p>thanks in advance</p>