title: MySQL using Sum and Case
body: <p>I'm trying to create a GridView with ASP.NET connecting to a MySQL database.  The data appears like below.</p>
  
  <pre><code>BusinessUnit    OrderDate      Canceled
  UnitA           1/15/2013          N
  UnitA           10/1/2013          N
  UnitB           10/15/2013         N
  UnitB           10/22/2013         N
  UnitB           10/22/2013         N
  </code></pre>
  
  <p>Based on the records above, I'd like the result to appear like below</p>
  
  <pre><code>BusinessUnit  TodaysOrders   ThisMonthsOrders  ThisYearsOrders
  UnitA              0                1                2
  UnitB              2                3                3
  </code></pre>
  
  <p>My current code is below.  It's giving me error (something about DatabaseName.sum does not exist. Check the 
  Function Name Parsing and Resolution' section... )</p>
  
  <pre><code>Select  
      SUM (CASE WHEN (OrderDate)=DATE(NOW()) THEN 1 ELSE 0 END) AS TodaysOrders,
      SUM (CASE WHEN YEAR(OrderDate) = YEAR(CURDATE()) AND MONTH(OrderDate) = MONTH(CURDATE()) THEN 1 ELSE 0 END) AS ThisMonthsOrders,
      SUM (CASE WHEN YEAR(main_order_managers.creation_date) = YEAR(CURDATE()) THEN 1 ELSE 0 END) AS ThisYearsOrders 
  </code></pre>
  
  <p>code continues</p>
  
  <pre><code>FROM OrderTable WHERE OrderTable.Canceled. &lt;&gt; 'Y';
  </code></pre>
  
  <p>Is Sum Case the best use here?</p>