title: How to do a for or while loop in Databricks SQL
body: <p>Does anyone know how to write a for or while loop in SQL in Databricks? I have tried many variations on the following SQL Server type code, but nothing seems to work. I can't seem to find any reference on it either. I would prefer not to do it in PySpark as I need to feed the output into more SQL code.</p>
  <pre><code>DECLARE @Counter INT 
  SET @Counter=1
  WHILE ( @Counter &lt;= 10)
  BEGIN
      PRINT 'The counter value is = ' + @Counter
      SET @Counter  = @Counter  + 1
  END
  </code></pre>
  <p>Any advice would be greatly appreciated.</p>
  <p>Thanks.</p>