title: Sql - Stored Procedure with While statement
body: <p>i'm trying to update some columns values using a stored procedure:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[UpdataObjectivesPosition] 
  @idGoal int
  AS
  BEGIN
  SET NOCOUNT ON;
  DECLARE @count int 
      SET @count = 1
  
      WHILE exists (SELECT * From Objective Where IDgoal = @idGoal)
      Begin
        Update [Tasks] Set Position=@count
        SET @count = @count + 1
      End
   END
   GO
  </code></pre>
  
  <p>But i get an infinite loop, i think its because of while expression.
  So how can I create this procedure correctly ? Please help me</p>
  
  <p>Example:</p>
  
  <h2>Name   Position</h2>
  
  <p>tskA     -   4 </p>
  
  <p>tskB   -     5 </p>
  
  <p>tskc       -     7 </p>
  
  <p>I want that the procedure sets the position to 1 , 2 , 3 , .......</p>