title: Query to get batch range on Size column not using ntile
body: <p>We are working on large set of records for process. we are doing batch wise process using NTILE Function right now.</p>
  
  <p>Please check on attached image example.  </p>
  
  <p>We are using currently NTILE function to make range then using ID column in between to process. </p>
  
  <p>As per new requirement, we have to make range based on Size column. 100 GB per batch.</p>
  
  <p>For example:</p>
  
  <pre><code>Batch 1 : 1 has 100 size So ID: 1 record only.
  Batch 2 : 2,3,4,5 (Total 100 GB) 
  Batch 3 : 6 ID has &gt; 100 so 1 record only
  etc. 
  </code></pre>
  
  <p>Please check attached screenshot for more understand. </p>
  
  <p>My Findings but not giving exact solution:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>DECLARE @intBatchSize BIGINT = 100;
  SELECT  y.ID, y.FileSize, y.RunningTotal
         ,DENSE_RANK() OVER (ORDER BY (y.RunningTotal / @intBatchSize) + 1) batch
  FROM    (SELECT i.ID, i.FileSize
                 ,RunningTotal = SUM(i.Size) OVER (ORDER BY i.ID) -- RANGE UNBOUNDED PRECEDING)
           FROM   dbo.Table1 AS i WITH (NOLOCK)
          ) y
  ORDER BY y.ID;</code></pre>
  </div>
  </div>
  </p>