title: Cursor loop infinite loop by using inser into
body: <p>I want to use a cursor for inserting data.</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[VehBlocMajStatut] 
  -- Add the parameters for the stored procedure here
  @NO_Veh int,
  @Statut int
  
  AS
  BEGIN
  
  DECLARE @Temp_appel int
  DECLARE appel_cursor CURSOR FOR 
  SELECT NO_APPEL FROM ESPMEDS_LS_APPVEH WHERE NO_VEHICULE = @NO_Veh
  
  OPEN appel_cursor;
  
  FETCH NEXT FROM appel_cursor INTO @Temp_appel;
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
      INSERT INTO ESPMEDS_LS_APPVEH (NO_VEHICULE, NO_APPEL, STATUT, DATEVEH)
      VALUES (@NO_Veh, @Temp_appel, @Statut, GETDATE())
  
      FETCH NEXT FROM appel_cursor INTO @Temp_appel;
  
  
  END
  close appel_cursor
  deallocate appel_cursor
  END
  </code></pre>
  
  <p>Unfortunately it turns into an infinite loop.  When I commented the <code>INSERT INTO</code> clause then it works normally.</p>
  
  <p>How can I do an insert with a cursor?</p>