title: How to Group by month when there's a turn of the month
body: <p>I have a table  with this template:</p>
  
  <p>Table_1</p>
  
  <pre><code>+----------+------------------+-----+
  | Code     |     DateTime     | Qty |
  +----------+------------------+-----+
  |        1 |08/31/2019 18:30  | 100 |
  |        1 |09/01/2019 18:30  | 150 |
  |        2 |09/03/2019 18:30  |  80 |
  |        2 |09/03/2019 18:30  | 100 |
  |        3 |10/15/2019 18:30  | 100 |
  +----------+------------------+-----+
  </code></pre>
  
  <p>And I need to group by Code, Year, Month and sum(Qty).</p>
  
  <p>I've already made the select for this table :</p>
  
  <pre><code>Select
      Year(DateTime) as Year,
      DATENAME(Month,Datetime) as Month,
      CODE,
      SUM(QTY) as Qty,
  
  From 
      Table_1
  
  Group by 
      Code,
      Year(DateTime),
      DATENAME(Month,Datetime)
  
  Order by Code
  </code></pre>
  
  <p>but when a Code has datetime in two differents months, that Code has two rows:</p>
  
  <pre><code>+----+-----------+-=---+-----+
  |Year|   Month   |Code | Qty |
  +----+-----------+-----+-----+
  |2019| August    |  1  | 100 |
  |2019| September |  1  | 150 |
  |2019| September |  2  | 180 |
  |2019| October   |  3  | 100 |
  +----+-----------+-----+-----+
  </code></pre>
  
  <p>How can get group by Code, in that case with rows in more than one months,
  considering the last one month, like:</p>
  
  <pre><code>+----+-----------+-=---+-----+
  |Year|   Month   |Code | Qty |
  +----+-----------+-----+-----+
  |2019| September |  1  | 250 |
  |2019| September |  2  | 180 |
  |2019| October   |  3  | 100 |
  +----+-----------+-----+-----+
  </code></pre>
  
  <p>Hope I was clear.</p>