title: TSQL Check if Month and Year fields are expired
body: <p>i have a table with Month and Year fields as integer, eg:</p>
  
  <pre><code>Month | Year 
  ------------
    10  |  17
  ------------
    11  |  17
  ------------
    12  |  17
  ------------
     1  |  18
  ------------
  </code></pre>
  
  <p>(Year 17 is for 2017 and Year 18 is for 2018)</p>
  
  <p>I want add into a query a calculated field for check if the date is expired</p>
  
  <pre><code>SELECT [Year], [Month],
      CASE WHEN 
          ([Year]+2000) &lt; DATEPART(Year, GetDate()) OR 
          (([Year]+2000) = DATEPART(Year, GetDate()) AND [Month] &lt; DATEPART(Month, GetDate())) 
     THEN 1 ELSE 0 END AS IsExpired
  FROM test
  </code></pre>
  
  <p>the output is</p>
  
  <pre><code>Month | Year | IsExpired
  ------------------------
    10  |  17  |    1
  ------------------------
    11  |  17  |    1
  ------------------------
    12  |  17  |    1
  ------------------------
     1  |  18  |    1
  ------------------------
  </code></pre>
  
  <p>the expected output is (because current GetDate() is 2017-11-29):</p>
  
  <pre><code>Month | Year | IsExpired
  ------------------------
    10  |  17  |    1
  ------------------------
    11  |  17  |    0
  ------------------------
    12  |  17  |    0
  ------------------------
     1  |  18  |    0
  ------------------------
  </code></pre>
  
  <p>see live on <a href="http://sqlfiddle.com/#!6/8c807/2" rel="nofollow noreferrer">http://sqlfiddle.com/#!6/8c807/2</a></p>
  
  <p>what i'm doing wrong?</p>