title: SQL WHILE Loops
body: <p>I have been working on creating a nested while loop in SQL, but having issues with the while loop. I think the main issue is with my outer loop. Any suggestions?  </p>
  
  <pre><code>USE HW_DB;
  IF OBJECT_ID('dbo.PythagoreanTriangles') IS NOT NULL
      DROP TABLE dbo.PythagoreanTriangles;
  GO
  
  CREATE TABLE PythagoreanTriangles
  (
      Side1 INT NOT NULL,
      Side2 INT NOT NULL,
      Hypotenuse FLOAT NOT NULL
  );
  
  DECLARE @side1 AS INT = 1;
  DECLARE @side2 AS INT = 1;
  DECLARE @count AS INT = 1;
  DECLARE @element  AS INT = 0;
  
  WHILE (@side1 = @count) 
      BEGIN
          WHILE @side2 &lt;= 10 BEGIN
              INSERT INTO dbo.PythagoreanTriangles
                  VALUES (@side1, @side2, SQRT((@side2 * @side2) + (@side1 * @side1)));
              UPDATE dbo.PythagoreanTriangles SET Hypotenuse = ROUND(Hypotenuse, 2)
  
          SET @side2 = @side2 + 1;
          SET @count = @count + 1;
          SET @element = @element + 1;
  
      IF @element = 10
      BEGIN 
      SET @side1 = @side1 + 1;
      SET @element = 0;
  
  END;
  END;
  END;
  </code></pre>
  
  <p>Output should look like the following:</p>
  
  <p>1 1 1.41
  <br />
  1 2 2.24
  <br />
  1 3 ...
  <br />
  1 4 ...
  <br />
  1 5 
  <br />
  1 6 
  <br />
  1 7 
  <br />
  1 8 
  <br />
  1 9 
  <br />
  1 10
  <br />
  2 2
  <br />
  2 3
  <br />
  2 4
  <br />
  2 5 
  <br />
  2 6
  <br />
  2 7 
  <br />
  2 8
  <br />
  2 9 
  <br />
  2 10
  <br />
  ..........
  <br />
  ........ etc</p>
  
  <p>9 9
  <br />
  9 10
  <br />
  10 10</p>