title: SQL sum with condition
body: <p>I currently have a large SQL statement which i add the following line to in order to get the total cash for each transaction ID (which are unique):</p>
  
  <pre><code>select sum(cash) from Table a where a.branch = p.branch 
  and a.transID = p.transID) TotalCash
  </code></pre>
  
  <p>and i now need to do the same but only total the cash values that have a valuedate within the last month, so i have something like this:</p>
  
  <pre><code>select sum(CASE ValueDate WHEN &gt; @startMonthDate THEN cash ELSE NULL END) 
  from Table a where a.branch = p.branch and a.transID = p.transID) TotalMonthCash
  </code></pre>
  
  <p>Sorry that I dont have the whole statement, but it is really long and specific to the context of the stored procedure but was hoping someone would know what i mean?</p>