title: Looping in SELECT statement in ms sqlserver
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7149271/sql-server-2008-generate-a-series-of-date-times">SQL Server 2008 Generate a Series of date times</a>  </p>
  </blockquote>
  
  
  
  <p>I have to Loop through a startDate and endDate</p>
  
  <p>The SELECT statement should produce result as..</p>
  
  <p>Expected Output :</p>
  
  <pre><code>------------
  Date
  ------------
  09/01/2012 -&gt; startDate
  09/02/2012
  09/03/2012
  .
  .
  .
  .
  09/30/2012 -&gt; endDate
  </code></pre>
  
  <p>i tried</p>
  
  <pre><code>declare @startDate datetime , @endDate endDate
  set @startDate='09/01/2012'
  set @endDate='09/30/2012'
  
  while DATEDIFF(@startDate,@endDate)!=-1
  begin
  select @startDate as Date
  set @startDate = DATEADD(day,2,@startDate)
  end
  </code></pre>
  
  <p>But its not working out..</p>
  
  <p>it generates 30 outputs..</p>
  
  <p>i want the dates in a single output as in the expected output..</p>
  
  <p>where am i going wrong here guys ?</p>