title: SQL Server : datetime incorrect results
body: <p>Using SQL Server 2008,</p>
  
  <p>I have a procedure as follows: </p>
  
  <pre><code>SELECT 
      UserId, Name, Company, LanguageId, CodeRegisteredWith, TotalLoggedInDuration, 
      Region, IsAdmin,
      IsRep, IsRetailer, IsTeamLeader, [dateregistered] 
  FROM 
      RoundupAcademy.dbo.UserProfile WITH(NOLOCK)
  WHERE 
      (Convert(smalldatetime, DateRegistered, 120) &gt;= Convert(smalldatetime, '2013-1-1', 120) 
      AND (Convert(smalldatetime, DateRegistered, 120) &lt;= convert(smalldatetime, '2013-8-8', 120)))
  </code></pre>
  
  <p>This works fine and shows the results between the dates.</p>
  
  <p>However when expanding on this query and some more conditions as follows:</p>
  
  <pre><code>SELECT 
     UserId, Name, Company, LanguageId, CodeRegisteredWith, TotalLoggedInDuration,     
     Region, IsAdmin, IsRep, IsRetailer, IsTeamLeader, [dateregistered] 
  FROM 
     RoundupAcademy.dbo.UserProfile WITH(NOLOCK)
  WHERE 
     UserId is not null OR UserId not like '' 
     AND 
     (@LanguageID = 0 OR ([LanguageID] = @LanguageID ))
     AND 
     ((Convert(smalldatetime, DateRegistered, 120) &gt;= Convert(smalldatetime, @datereg,  120) 
  AND (Convert(smalldatetime, DateRegistered, 120) &lt;= convert(smalldatetime, @dateend, 120))))
  </code></pre>
  
  <p>it seems any date shows.</p>
  
  <p>not sure what the problem is as my other conditions look fine.</p>
  
  <p>any ideas?</p>