title: Loop through range of dates in SQL Server
body: <p>I have a stored procedure that looks like : </p>
  
  <pre><code>CREATE procedure [dbo].[SP_EXEC] 
  AS
     DECLARE @DATE AS varchar(50)
  
     SET @DATE = (SELECT TOP(1) CONVERT(VARCHAR, YEAR(DATEADD(MM, DATEDIFF(MM, '01/01/2000', DATEADD(MM, -1, GETDATE())), '01/01/2000'))) + RIGHT('00'+ CONVERT(VARCHAR, MONTH(DATEADD(MM, DATEDIFF(MM, '01/01/2000', DATEADD(MM, -1, GETDATE())), '01/01/2000'))), 2) + RIGHT('00' + CONVERT(VARCHAR, DAY(DATEADD(MM, DATEDIFF(MM, '01/01/2000', DATEADD(MM, -1, GETDATE())), '01/01/2000'))), 2)
                  FROM produit)
  
      EXEC SP_DELETE_lIGNE_MOIS_EN_COURS  @DATE
  </code></pre>
  
  <p>The stored procedure works fine, my goal is to do a loop of a range of date from 2012/03/01 to the current date. How to update my stored procedure to do an update on history ?</p>