title: T-SQL error: Adding a value to a 'smalldatetime' column caused overflow. SQL server bug?
body: <p>When I try to execute the following code, I get error "Adding a value to a 'smalldatetime' column caused overflow":</p>
  
  <pre><code>DECLARE @t TABLE (ID UNIQUEIDENTIFIER, BegDate SMALLDATETIME, EndDate SMALLDATETIME)
  
  INSERT INTO @t
  SELECT NEWID(), '19000101', '20151124'
  
  -- This is to show you that nothing is really selected
  SELECT 'You will never see it'
  FROM @t r1
  INNER JOIN @t r2 ON r2.ID = r1.ID
  WHERE   1=1
      AND r1.BegDate &gt; r2.BegDate    
      AND r1.EndDate &lt;= r2.EndDate
  
  SELECT r1.ID, r2.BegDate, DATEADD(DAY, -1, r1.BegDate) AS EndDate
  FROM @t r1
  INNER JOIN @t r2 ON r2.ID = r1.ID
  WHERE   1=1
      AND r1.BegDate &gt; r2.BegDate  -- This guarantees that r1.BegDate is not minimal value
      AND r1.EndDate &lt;= r2.EndDate
  </code></pre>
  
  <p>As you can see, result of DATEADD() cannot be less than minimal value. Moreover, DATEADD() must not be called, because SELECT must return nothing.
  Is it an SQL server bug?</p>