title: sql while loop with date counter
body: <p>I need to do something like this in sql:</p>
  
  <pre><code>declare @StartDate varchar(10)
  declare @EndDate varchar(10)
  set @StartDate='12/31/2008'
  set @EndDate='1/11/2009'
  
  Declare @date varchar = @StartDate
  while (@date &lt;= @EndDate)
  begin
   -- some statements
  set @date += 1 -- basically increment by 1 day
  end
  </code></pre>
  
  <p>How can I do the above correctly in SQL?  Basically, my startdate and enddate are strings and not datetimes because my business logic is referencing string column in another table with a date as the name of the column-But I need to loop through a bunch of columns, each column having the name of the next day's date.</p>
  
  <p>If the date is 11/07/2009, the name of the column would be '11/7/2009' (without the 0 in the 7), so I have to watch out for that too.</p>
  
  <p>Any help is appreciated!</p>
  
  <p>Thanks.</p>