title: Can't convert Datetime to Int
body: <p>I am trying to <code>SELECT</code> rows based on two values with this stored procedure:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[MYSelect]
  
      -- Parameters with default values
      @MitarbeiterId          AS int,
      @Wann                   AS datetime2(7)
  
  AS
  
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
          SET NOCOUNT ON;
  
          SELECT  *
          FROM    [Plan] 
          WHERE   RefMitarbeiterId    =   @MitarbeiterId
          AND     Jahr                &lt;=  YEAR(@Wann)
          AND     Monat               &lt;=  MONTH(@Wann)
          AND     Abgeschlossen       =   0
  </code></pre>
  
  <p>The problem is the following part:</p>
  
  <pre><code>        AND     Jahr                &lt;=  YEAR(@Wann)
          AND     Monat               &lt;=  MONTH(@Wann)
  </code></pre>
  
  <p>I don't know why this part is causing a (syntax) problem. With this lines included, using MSSQL Studio, I receive an error <code>unable to convert DateTime to Integer</code>. Removing these returns results and has no syntax error. I use <code>YEAR()</code> and <code>MONTH()</code> elsewhere, so I'm confused why there is a problem here.</p>
  
  <p>This is the <code>Plan</code> table:</p>
  
  <p><img src="https://i.stack.imgur.com/yLkpb.png" alt="Plan Table"></p>