title: Bulk insert using loop
body: <p>I have been trying to insert 500 records into a table (<code>dbo.Product</code>) but I am getting this error:</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 31<br>
    Incorrect syntax near 'p'</p>
  </blockquote>
  
  <p>Here is my query:</p>
  
  <pre><code>DECLARE @StartLoop INT,
          @EndLoop INT,
          @ProductID INT,
          @ProductName NVARCHAR(250),
          @BestBefore DATETIME,
          @ManufactureDate datetime,
          @ProductNumber NVARCHAR(25),
          @Weight decimal, 
          @ProductStockLevelID INT 
  
  SELECT 
      @StartLoop =1,
      @EndLoop = 500,
      @ProductID  = '',
      @ProductName = 'Yoghurt',
      @BestBefore = '',
      @ManufactureDate = '' ,
      @ProductNumber = '',
      @Weight = '', 
      @ProductStockLevelID = ''
  
  WHILE @StartLoop &lt;= @EndLoop
  BEGIN
      INSERT INTO dbo.Product p (ProductID, ProductName, BestBefore, ManufactureDate, ProductNumber, [Weight], ProductStockLevelID)
          SELECT 
              @ProductID  + CAST(@StartLoop AS INT),
              @ProductName + Cast(@startloop AS  NVARCHAR(250)),
              @BestBefore + CAST(@StartLoop AS DATETIME),
              @ManufactureDate + CAST(@startLoop AS DATETIME),
              @ProductNumber + CAST(@StartLoop AS Nvarchar(25)),
              @Weight + CAST(@StartLoop AS DECIMAL),
              @ProductStockLevelID + CAST(@StartLoop AS INT)
  
      SELECT @StartLoop = @StartLoop + 1 
  END 
  </code></pre>
  
  <p>Can someone please tell me what I am doing wrong?</p>
  
  <p>Thank you in advance.</p>