title: Conversion failed when converting the nvarchar value 'YES' to data type int
body: <p>The following query is enumerate through about a million rows to calculate MTBUR (Mean Time Between Unscheduled Repair):</p>
  
  <pre><code>DECLARE @BeginDate date = '01-01-2013', 
          @EndDate date = '12-31-2013'
  BEGIN
      SELECT  H.AutoType
             ,COALESCE(SUM(CASE WHEN (R.ReceiveDate BETWEEN @BeginDate AND @EndDate) 
                               THEN H.Hours ELSE 0 END)
                      / COUNT(CASE WHEN (R.ReceiveDate BETWEEN @BeginDate AND @EndDate) 
                            AND (R.Confirm NOT LIKE 'C%' AND R.Confirm NOT LIKE 'Y%') 
                              THEN R.Confirm ELSE 0 END)
                  , SUM(H.Hours)) AS 'MTBUR'
      FROM [Hours] H
      INNER JOIN Repair R   ON H.SN = R.SN 
      GROUP BY H.AutoType
      ORDER BY AutoType ASC
  END 
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <pre><code>Msg 245, Level 16, State 1, Line 4
  Conversion failed when converting the nvarchar value 'YES' to data type int.
  </code></pre>
  
  <p>I'm deducing that the <code>YES</code> from the error message is the boolean evaluation result from the first 'CASE' statement; correct me if I'm wrong.</p>
  
  <p>The following is my pseudocode:</p>
  
  <pre><code>The numerator is the sum of all hours between @BeginDate and @EndDate
  The denominator is the COUNT of all confirmed status NOT LIKE %C and NOT LIKE %Y AND between @BeginDate and @EndDate.
  </code></pre>
  
  <p>I've been tinkering with this query for days; yes, im a newbie but learning.  Would love to finish this up and move on to next sprint</p>