title: Calacuted field in SQL SELECT statement
body: <p>I have a query which give 4 columns</p>
  
  <p>EXPR1, EXPR2, MOVE5 and qty</p>
  
  <p>qty is the same value for all (6360)</p>
  
  <p>I want to be able to adapt the query so that a new calculated field is generated for each row which is the qty + EXPR2 but the qty used from each row will be the result from the previous calculation but starting from the initial qty.</p>
  
  <pre><code>e.g. 
  row 1 (1,400,6360,6360)
  row2 (-10,401,6360,6350)
  row3 (-1,402,6360,6349)  etc
  
  
  SELECT
      movement_reference AS EXPR1,
      movement_quantity AS EXPR2,
      CAST (CAST(movement_date AS INT) AS VARCHAR(5)) + RIGHT('00000' + CAST(CAST(sequence_no AS INT) AS VARCHAR(6)), 6) AS MOVE5,
      (SELECT physical_qty FROM  stocktable WHERE (product = 'B') AND (warehouse = 'FH')) AS qty
  FROM
      stockhistory
  WHERE
      (warehouse = 'FH') 
  AND
      (product = 'B')
  ORDER BY
      dated DESC
  </code></pre>
  
  <p>Using SQL Server 2000.</p>