title: SQL query to select records between two dates using only year and month
body: <p>I have a initial and final date, for example: <code>01/06/2018</code> and <code>01/03/2019</code> and I want to get the records stored in the SQL Server database but only using year and month.</p>
  
  <p>I've tried this code but it does not return me any record. I also tried the code but only with the YEAR limitation (removed the month) and returns all records between those two years.</p>
  
  <pre class="lang-vb prettyprint-override"><code>If tem_permissao Then
  
    Set conn = New ADODB.Connection
    Set rsImportar = New ADODB.Recordset
  
    'gets the year and month from inital and final year and month                              
    date1 = .Cells(iRowNo, 2)
    init_year = Year(date1)
    init_month = Month(date1)
    date2 = .Cells(iRowNo, 3)
    fin_year = Year(date2)
    fin_month = Month(date2)
  
    conn.Open sConnString
    Set rsImportar = conn.Execute("SELECT INSTALATION, VALUE, USER, DATA, HISTORIC FROM dbo.VALUES WHERE ID_VARIAVEL = " &amp; sID_VARIAVEL &amp; " AND YEAR &gt;= " &amp; init_year &amp; " AND YEAR &lt;= " &amp; fin_year &amp; " AND MONTH &gt;= " &amp; init_month &amp; " AND MONTH &lt;= " &amp; fin_month &amp; ";") 
  
    ' Transfer result
  
    Sheets(2).Range("D2").CopyFromRecordset rsImportar
  
    rsImportar.Close
  
    TRANSFERED = TRANSFERED + 1
    .Cells(iRowNo, 9).Value = "Record Transfered"
  
  End If
  </code></pre>