Trouble accumulating data from specific time interval last year <p>I'm trying to accumulate an amount from a SQL query. The inputs <code>@STARTDATE</code> and <code>@ENDDATE</code> is a datetime type (YYYYMMDD).<br> So the Case statements check if the date of the verification is between the specific dates.</p> <p>Some explanations of the Case statements: Works fine:<br> CURRENT_YEAR_ACC, accumulates the current years amounts of verifications from the beginning of the year to @ENDDATE</p> <p>CURRENT_YEAR_MONTHS, the accumulated amounts between @STARTDATE and @ENDDATE.</p> <p>PREVIOUS_YEAR_MONTH, last years accumulated amounts between @STARTDATE -1 yr and @ENDDATE -1 yr.</p> <p>Does not work: </p> <p>PREVIOUS_YEAR_ACC, should calculate beginning of last year (20XX-01-01) to the @ENDDATE -1yr. </p> <p>Here I get the same value as PREVIOUS_YEAR_MONTH</p> <pre><code> sum (RAW_DATA.CURRENT_YEAR_MONTH) as PERIOD_I_AR, sum (RAW_DATA.PREVIOUS_YEAR_MONTH) as PERIOD_FG_AR, sum (RAW_DATA.CURRENT_YEAR_ACC) as ACK_I_AR, sum (RAW_DATA.PREVIOUS_YEAR_ACC) as ACK_FG_AR from (SELECT rehuv.[KD1] as VST_nr, rekod.BEN as VST_ben, rehuv.KONTO as Konto_nr, rektk.KONTO_BEN as Konto_ben, lresk.LEV_NR as LEV_nr, rehuv.TEXT as LEV_ben, rehuv.VER_DATUM as DATUM, case when rehuv.VER_DATUM &gt; = dateadd (month, - datepart (month, @STARTDATE) + 1, @STARTDATE) and rehuv.VER_DATUM &lt; = @ENDDATE then rehuv.BELOPP else 0 end as CURRENT_YEAR_ACC, case when rehuv.VER_DATUM &gt; = dateadd (YEAR, - 1, dateadd (MONTH, - datepart (MONTH, @STARTDATE) + 1, @STARTDATE)) and rehuv.VER_DATUM &lt; = DATEADD (year, - 1, @ENDDATE) then rehuv.BELOPP else 0 end as PREVIOUS_YEAR_ACC, case when rehuv.VER_DATUM &gt; = @STARTDATE and rehuv.VER_DATUM &lt; = @ENDDATE then rehuv.BELOPP else 0 end as CURRENT_YEAR_MONTH, case when rehuv.VER_DATUM &gt; = DATEADD (year, - 1, @STARTDATE) and rehuv.VER_DATUM &lt; = DATEADD (year, - 1, @ENDDATE) then rehuv.BELOPP else 0 end as PREVIOUS_YEAR_MONTH FROM [FTG0001].[dbo].[REHUV] </code></pre>