title: COUNT results from SQL Query with a HAVING clause
body: <p>Are you able to use COUNT in a query with a HAVING clause so that the COUNT returns the number of rows?  When I try, Im getting the count of the number of times the ID shows up in the table.  Here is the query:  </p>
  
  <pre><code>SELECT col_appid, min(col_payment_issued_date) as PayDate  
  FROM tbl_ui_paymentstubs  
  WHERE isnull(col_payment_amount,0) &gt; 0  
  GROUP BY col_appid  
  HAVING min(col_payment_issued_date) &gt;= '09/01/2010' and min(col_payment_issued_date) &lt;= '09/30/2010'
  </code></pre>
  
  <p>I get back 6 rows, which is fine, but i'd like to just get back the number 6.</p>
  
  <p>I found I could do it this way, but was wondering if there was another, more elegant way:</p>
  
  <pre><code>WITH Claims_CTE(AppID, PayDate) as
  (  
   SELECT col_appid, min(col_payment_issued_date) as PayDate
   FROM tbl_ui_paymentstubs
   WHERE isnull(col_payment_amount,0) &gt; 0
   GROUP BY col_appid
   HAVING min(col_payment_issued_date) &gt;= '09/01/2010' and min(col_payment_issued_date) &lt;= '09/30/2010'
  )  
   SELECT count(AppID) as Amount from Claims_CTE
  </code></pre>
  
  <p>`</p>