title: Adding Current Values to future Dates SQL
body: <p>I'm trying to load data for future dates. My scenario is something like this, I have data for 2016, 2017 and 2018(until August). Each year has Current and 'Prior Year Same Day' values associated. Data is aggregated to Month. Requirement is that I load data for future dates as well, that is for September 2018 through August 2019 using 'PYSD' values. For example, the 'Current' value for September 2017 will be 'PYSD' value for September 2018 and so on. When I try this particular logic I get an error stating 'overflow' and I'm unable to figure out what's causing. This happens only with the second condition in my WHERE clause. My SELECT clause aggregates a months' data and outputs as '08-01-2018' - there will be one row per month/year.</p>
  
  <pre><code>SELECT 
      CAST(YEAR(DATEADD(dd, 364, CalendarDate)) AS VARCHAR(250)) 
       + '-' + RIGHT('00' + CAST(MONTH(DATEADD(dd, 364, CalendarDate)) AS VARCHAR(250)), 2) 
       + '-' + '01' AS MonthPeriod 
  FROM
      DateTable 
  WHERE  
      DATEADD(DD, 364, CalendarDate) &gt; '08-31-2018' 
      AND DATEADD(DD, 364, CalendarDate) &lt; '08-01-2019'
  </code></pre>
  
  <p>My error:</p>
  
  <blockquote>
    <p>Msg 517, Level 16, State 3, Line 1<br>
    Adding a value to a 'date' column caused an overflow.</p>
  </blockquote>
  
  <p>Also, open to suggestions if there is a simpler way. I'm on SQL Server.</p>
  
  <p>TIA.</p>
  
  <p>Added sample data:</p>
  
  <p><a href="https://i.stack.imgur.com/w4yWN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w4yWN.jpg" alt="enter image description here"></a></p>