title: SQL Server Cursors and Group By
body: <p>I need to use a cursor with Group by statement based on group number from my table:
  The current code I have gives me each record lets say for group 1 separately, which I do not want, I want the data to be retrieved grouped by.</p>
  
  <pre><code>DECLARE hello CURSOR
      FOR 
  
  SELECT bygpno, SUM(bycash)
      FROM sheet1 
      GROUP BY bygpno
      ORDER BY bygpno
  
  
  OPEN hello
  FETCH NEXT FROM hello
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
  
  FETCH NEXT FROM hello
  
  END
      CLOSE hello
      DEALLOCATE hello
  </code></pre>
  
  <p>When I run the above it retrieves one line at a time in the result, which I do not know why. </p>