title: SQL SUM filter query
body: <p>We have a table with the following information:
  <a href="http://i.stack.imgur.com/SdQT1.jpg" rel="nofollow">table1</a></p>
  
  <p>I need T-SQL code that receives a "start date" and "end date and would generate the invoice total, grouped by customer id and invoice type, of all invoices generated within the date range AND the total invoiced for that customer (credit and cash combined).</p>
  
  <p>For instance, the result if we provide start date 01-10-2012 and end date 10-11-2012 should be:</p>
  
  <p><a href="http://i.stack.imgur.com/pFE7f.jpg" rel="nofollow">result_table</a></p>
  
  <p>This is what I have:</p>
  
  <pre><code>DECLARE @startdate DATE, @enddate DATE    
  SET @startdate = '01-10-2012'       
  SET @enddate = '10-11-2012'
  
  SELECT CustomerId, InvoiceType, SUM(Total) As Total
  FROM Invoices       
  WHERE Date BETWEEN @startdate AND @enddate
  GROUP BY CustomerID, InvoiceType
  </code></pre>
  
  <p>It works fine, but I am unable to come up with a way to calculate the "total2" column, since I'm already grouping rows by "invoicetype".</p>
  
  <p>Help, please.</p>
  
  <p>Thank you.</p>