title: SQL Server : OUTER JOIN with GROUP BY clause doesn't return all possible combinations?
body: <p>I am querying two tables:</p>
  
  <ol>
  <li><code>tblPurhcaseOrders</code> - holds purchase orders with various columns, one of which is a foreign key called <code>OrderTypeID</code></li>
  <li><code>tblOrderTypes</code> - holds 4 types of purchase orders</li>
  </ol>
  
  <p>One of the order types in <code>tblOrderTypes</code> was added later than the first 3 basic ones. Thus,  instances of purchase orders with this newer order type appear only from a certain point of time (Feb. 2012).</p>
  
  <p>I'm writing an aggregated query which should ultimately bring me the sum of all purchase orders, grouped by their type.</p>
  
  <p>I do want the results to me 0 or NULL, even if I query a point of time in which the newer order type had not existed yet.</p>
  
  <p>Here's how my query looks like:</p>
  
  <pre><code>SELECT
     MONTH(tblPurchaseOrders.DeliveryDate) AS sMonth,
     YEAR(tblPurchaseOrders.DeliveryDate) AS sYear, 
     tblOrderType.OrderTypeName,
     SUM(ISNULL(TotalPrice,0)) AS sValue 
  FROM        
     tblPurchaseOrders 
  RIGHT OUTER JOIN 
     tblOrderTypes ON tblPurchaseOrders.OrderTypeID = tblOrderTypes.OrderTypeID  
  WHERE       
     MONTH(DeliveryDate) = 1  
     AND YEAR(DeliveryDate) = 2012
  GROUP BY
     MONTH(DeliveryDate), YEAR(DeliveryDate), tblOrderType.OrderTypeName
  </code></pre>
  
  <p>Now, the query above works just fine and provides me with correct aggregation, only it leaves out the newer order type (reminder, it didn't exist in JAN-2012 yet).</p>
  
  <p>If I change the query condition to <code>MONTH(DeliveryDate) = 2 AND YEAR(DeliveryDate) = 2012</code> it appears.</p>
  
  <p>I've tried full join and also tried switching between the order of the two tables and toggled to <code>LEFT OUTER JOIN</code>, no luck.</p>