title: Calculate running total while inserting into temporary table
body: <p>I have the below query which is calculating the total. I want to calculate running total instead of total. How can I modify the query? </p>
  
  <p>Please don't flag it as duplicate, as I have to modify things within this query to get the desired result. The query building is done dynamically with windows application user selection.</p>
  
  <pre><code>IF OBJECT_ID('tempdb..#mytemptable') IS NOT NULL
      DROP TABLE #mytemptable;
  
  SELECT
      SUM(CAST([PT_100SCALED_VAL0] AS bigint)) AS PT_100SCALED_VAL0_TOTAL INTO #MYTEMPTABLE
  FROM (
      SELECT
          t1.[timestamp],
          t1.[PT_100SCALED_VAL0]
      FROM [REPORT] t1
      WHERE CONVERT(DATE, t1.[timestamp]) = @timestamp
  ) TEMPTABLE
  
  SELECT
      t1.[timestamp],
      t1.[PT_100SCALED_VAL0],
      RM_temp.*
  FROM    [REPORT] t1,
          #MYTEMPTABLE RM_temp
  WHERE
      CONVERT(DATE, t1.[timestamp]) = @timestamp
  </code></pre>
  
  <p>My present result is like below:</p>
  
  <pre><code>[timestamp]             [PT_100SCALED_VAL0] PT_100SCALED_VAL0_TOTAL
  31/May/2016 12:01:37 PM 1                   87173
  31/May/2016 12:02:07 PM 2                   87173
  31/May/2016 12:02:37 PM 3                   87173
  31/May/2016 12:03:07 PM 4                   87173
  </code></pre>
  
  <p>I want it to be:</p>
  
  <pre><code>[timestamp]             [PT_100SCALED_VAL0] PT_100SCALED_VAL0_TOTAL
  31/May/2016 12:01:37 PM  1                  1
  31/May/2016 12:02:07 PM  2                  3
  31/May/2016 12:02:37 PM  3                  6
  31/May/2016 12:03:07 PM  4                  10
  </code></pre>