title: Count up a variable in a while loop using EXEC
body: <p>I have another question and hope u can help me!</p>
  
  <p>I need a while loop in which I execute (EXEC) a command using a variable (here: @SETi) I defined before. Amongst others, the variable 'i' I use for the while loop has to be count up.</p>
  
  <p>Here a very small piece of my code:</p>
  
  <pre><code>DECLARE @i int
  SET @i = 1
  
  DECLARE @SETi nvarchar(max)
  
  WHILE @i &lt;= 10
  
      BEGIN
  
          -- Tabelle definieren
  
          SET @SETi = 'SET '+CAST((@i) as nvarchar(max))+' += 1'
  
          EXEC (@SETi)
  
      END
  </code></pre>
  
  <p>First of all the loop isn't stopping.. And I get the warning: Incorrect syntax near '1'.</p>
  
  <p>Why is that?</p>
  
  <p>Thanks a lot!! T.R.</p>