title: Problem with Sql Server query using BETWEEN in where with DATETIME
body: <p>I have a Stored Procedure that loops through the months in the fiscal year and does a count for the items in each month.  I know for a fact there are 176 items, but when I run this it returns a total count of 182.  I tried removing one second from @EndDate, but then my total count was 165.  So I'm either counting items twice, or not counting all of them.  Can anyone help with what I'm doing wrong here?  Below is a stripped down version of what I'm doing:</p>
  
  <pre><code>DECLARE @Date DATETIME
  DECLARE @EndDate DATETIME
  
  SELECT @Date = CAST((@Year - 1) as VARCHAR) + '-07-01'
  SELECT @EndDate = DATEADD(Month, 1, @Date)
  
  
  DECLARE @Count INT
  SELECT @Count = 0
  WHILE @Count &lt; 12
  
  BEGIN
  
      SELECT 
          COUNT(yai.ID)
      FROM
          table_1    yai 
          INNER JOIN table_2 yat ON yai.ID = yat.ID 
      WHERE
          (yat.Date_Received BETWEEN CONVERT(VARCHAR, @Date, 101) AND CONVERT(VARCHAR, @EndDate, 101))  AND 
          yai.Pro_Type = @Value AND yat.Type = 'PC'
  
      SELECT @Count = @Count + 1
      SELECT @Date = DATEADD(MONTH, 1, @Date)
      SELECT @EndDate = DATEADD(MONTH, 1, @EndDate)
  
  END
  </code></pre>