title: mssql filter by date range
body: <p>I'm writing a little query that builds a count of rows per month&amp;year, to mimic the behavior you'd see in google analytics.</p>
  
  <p>this is my query:</p>
  
  <pre><code>USE MyDatabase;
  
  SELECT
      COUNT(*) AS Rows,
      DATENAME(mm, OpenDate) AS Month,
      DATENAME(yyyy, OpenDate) AS Year
  FROM MyTable
  WHERE Priority = 1
  GROUP BY DATENAME(mm, OpenDate), DATENAME(yyyy, OpenDate)
  ORDER BY Year, Month DESC;
  </code></pre>
  
  <p>I'm unclear as to how I'd apply a date range filter in this query.</p>
  
  <ol>
  <li>Should I use <code>HAVING</code> or <code>WHERE</code>?</li>
  <li>Do I need to use a fully formed datetime string for my vars? or do I filter by year and months separately since I've got those columns?</li>
  </ol>