title: SQL like syntax using date YYYY
body: <p>I've been given part of a project financial reporting system to work on. Basically, I'm trying to modify an existing query to restrict returned results by date in a field which contains a variable date format. </p>
  
  <p>My query is being sent the date from someone elses code in the format YYYY twice, so e.g. 2014 and 2017. In the SQL query below they are listed as 2014 and 2017, so you'll just have to imagine them as variables..</p>
  
  <p>The fields in the database which have the variable date forms come in two forms: YYYYMMDD or YYYYMM.</p>
  
  <p>The existing query looks like:</p>
  
  <pre><code>SELECT   
                      'Expense' AS Type,
                      dbo.Department.Description AS [Country Name],
                      dbo.JCdescription.Description AS Project,
                      dbo.Detail.AccountCode AS [FIN Code], 
                      dbo.JCdescription.ReportCode1 as [Phase Date Start], 
                      dbo.JCdescription.ReportCode2 as [Phase Date End], 
                      dbo.JCdescription.ReportCode3 as [Ratification Date], 
                      dbo.Detail.Year AS [Transaction Year], 
                      dbo.Detail.Period AS [Transaction Year Period], 
                      ...
                  FROM
                      dbo.Detail
                  INNER JOIN
                      ...
                  WHERE
                      (dbo.Detail.LedgerCode = 'jc')
                  ...
                  AND
                      (dbo.Detail.Year) BETWEEN '2014 AND 2017";
  </code></pre>
  
  <p>Ideally I'd like to change the last line to:</p>
  
  <pre><code>(dbo.JCdescription.ReportCode2 LIKE '[2014-2017]%')
  </code></pre>
  
  <p>BUT this searches for all the digits 2,0,1,4,5 instead of everything between 2014 and 2017.</p>
  
  <p>I'm sure I must be missing something simple here, but I can't find it! I realise I could rephrase it as <code>LIKE '201[4567]%'</code> but this means searches outside of 2010-2020 will error.. and requires me to start parsing the variables sent which will introduce an additional function which will be called a lot. I'd rather not do it. I just need the two numbers, 2014 and 2017 to be treated as whole numbers instead of 4 digits!</p>
  
  <p>Running on MS SQL server 10.0.5520</p>