title: SQL: Counting rows resulting from a join
body: <p>I am using SQL Server 2008 R2 and have the following query. I essentially trying to return two columns, the Employee's name and a count of the total number of calls they have made for the current month. I have gotten the query to run, but when it does it is taking quite a while and it returns huge incorrect numbers for the count of total calls.  Can anyone give me a hand with this? </p>
  
  <pre><code>Select A.Name, count(1) As TotalCalls
  From Calls B INNER JOIN Employees A on B.EmployeeID = A.TechID
  Where A.Name IN ('Steven', 'John', 'Mark', 'Jason', 'Tom') 
  AND Month(B.CreationDate) = Month(GetDate()) and Year(B.CreationDate) = Year(GetDate())
  Group By A.Name
  </code></pre>
  
  <p>Edit:
  I have tried the following query and I think I am pretty close now.  It is returning a result set that is accurate, I'm just not sure how to make this query only look at the current month. </p>
  
  <pre><code>Select A.Name, B.CallCount                                  
  From Employees A Inner Join (Select EmployeeID, Count(*) As CallCount From Calls Group By EmployeeID) B
  On A.TechID = B.EmployeeID
  Where A.Name IN ('Steven', 'John', 'Mark', 'Jason', 'Tom') 
  Group By A.Name, B.CallCount
  </code></pre>