title: How do I calculate a running total in SQL without using a cursor?
body: <p>I'm leaving out all the cursor setup and the SELECT from the temp table for brevity. Basically, this code computes a running balance for all transactions per transaction.</p>
  
  <pre><code>WHILE @@fetch_status = 0
  BEGIN
  
      set @balance = @balance+@amount
  
      insert into @tblArTran values ( --from artran table
                  @artranid, @trandate, @type, 
                  @checkNumber, @refNumber,@custid,
                  @amount, @taxAmount, @balance, @postedflag, @modifieddate )
  
  
      FETCH NEXT FROM artranCursor into 
              @artranid, @trandate, @type, @checkNumber, @refNumber,
              @amount, @taxAmount,@postedFlag,@custid, @modifieddate
  
  END
  </code></pre>
  
  <p>Inspired by this code from an answer to another question,</p>
  
  <pre><code>SELECT @nvcConcatenated = @nvcConcatenated + C.CompanyName + ', '
  FROM tblCompany C
  WHERE C.CompanyID IN (1,2,3)
  </code></pre>
  
  <p>I was wondering if SQL had the ability to sum numbers in the same way it's concatonating strings, if you get my meaning. That is, to create a "running balance" per row, without using a cursor.</p>
  
  <p>Is it possible?</p>