title: SQL Sum MTD & YTD
body: <p>I have only just started looking into SQL.</p>
  
  <p>I have a SQL Server 2008 r2 database that will return two fields DocDate &amp; InvValue. I need to sum the InvValues as MTD &amp; YTD as of Today's Date  So it looks like</p>
  
  <pre><code>**Period** ///////  **Total value**
  MTD        ////////////111111.11
  YTD       /////////////999999.99
  </code></pre>
  
  <p>I have done a fair amount of Googling and can do one or the other with SUM &amp; DATEPART, but I am stuck with trying to do both.</p>
  
  <p>Can someone give me some pseudo-code that would help me google a little further.</p>
  
  <p>Thank you @Gordon Linoff, That helped a lot and I learned something, That I will find useful in the future.
  My code now looks like:</p>
  
  <pre><code>SELECT
  SUM(CASE WHEN YEAR(T1.[DocDate]) = YEAR(GETDATE()) THEN T0.[TotalSumSy] END) AS YTD,
  SUM(CASE WHEN YEAR(T1.[DocDate]) = YEAR(GETDATE()) AND MONTH(T1.[DocDate]) = MONTH(GETDATE()) THEN T0.[TotalSumSy] END) AS MTD
  
  FROM [dbo].[INV1] T0 INNER JOIN [dbo].[OINV] T1 ON T1.[DocEntry] = T0.[DocEntry]
  </code></pre>
  
  <p>However I now get</p>
  
  <pre><code>YTD.........MTD
  99999.99....111111.11
  </code></pre>
  
  <p>And I need</p>
  
  <pre><code>YTD........99999.99
  MTD........11111.11
  </code></pre>
  
  <p>Any further assistance would be appreciated.</p>