title: SQL Server INSERT in Loop
body: <p>I have this SQL Script:</p>
  
  <pre><code>DECLARE @Loop INT
  SET @Loop = 1
  DECLARE @Result table([1] int, [2] int,[3] int,[4] int,[5]);
  
  WHILE (@Loop &lt;=5)
  BEGIN
  
  INSERT INTO @Result(@Loop)
   SELECT Id FROM Students WHERE Id=@Loop
  
  SET @Loop= @Loop+ 1
  END
  </code></pre>
  
  <p>I got an error in this line:</p>
  
  <pre><code>INSERT INTO @Result(@Loop)
  </code></pre>
  
  <p>Is it possible to use this way to insert data into column names using loop ? I mean dynamicaly </p>
  
  <p>Thanks</p>