title: How can I make a total sum for rows that have the same accname account in SQL server
body: <p>I'm trying to run a query that will tell me total sum (credit) of each same item that enter in the same month and have the same mainacc, subacc. The reason I have multiple lines for the same item and no total sum </p>
  
  <pre><code>SELECT MovingBudget.mainacc, MovingBudget.subacc, MovingBudget.accname, MovingBudget.movingbudgetmony, ChequeRecord.credit,ChequeRecord.docdate,                        DATEDIFF(MM,ChequeRecord.docdate, GETDATE()),    DATEDIFF(YY,ChequeRecord.docdate, GETDATE()),
      SUM(CASE WHEN DATEDIFF(MM, ChequeRecord.docdate, GETDATE()) =0 THEN ChequeRecord.credit END)  AS monthmove, 
        SUM(CASE WHEN DATEDIFF(MM, ChequeRecord.docdate, GETDATE()) &gt;= 1 THEN ChequeRecord.credit END) AS modawer,
      SUM(CASE WHEN DATEDIFF(yy, ChequeRecord.docdate, GETDATE()) = 0 THEN ChequeRecord.credit END) AS summation
  
                 FROM  
                  ChequeRecord INNER JOIN
                  MovingBudget 
                  ON ChequeRecord.accname = MovingBudget.accname
      WHERE 
      (SUBSTRING(MovingBudget.mainacc, 1, 1) = '1') 
      AND (SUBSTRING(MovingBudget.subacc, 1, 1) = '1') 
  
      GROUP BY MovingBudget.mainacc, MovingBudget.subacc, MovingBudget.accname, MovingBudget.movingbudgetmony, ChequeRecord.credit,ChequeRecord.docdate;
  </code></pre>
  
  <p>I can not come up with a SELECT query that will get me the total sum  for each item. Any help would be greatly appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I added image to show the context but it contains arabic words only:</p>
  
  <p><a href="https://i.stack.imgur.com/GMlMQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GMlMQ.png" alt="enter image description here"></a></p>