title: SQL YEAR(GETDATE())
body: <p>I'm currently working on a query that returns records from within a date range. The ideal is for the start date to be everything from 2015 onward. In theory, shouldn't each of the three SET statements below set the variable to 2015*?</p>
  
  <pre><code>DECLARE @startDate datetime;
  SET @startDate = '20150101';
  SET @startDate = YEAR(GETDATE());
  SET @startDate = DATEPART(yyyy,GETDATE());
  </code></pre>
  
  <p>Only the first one, the hardcoded date, behaves as expected. The other two return ALL records that are being queried through. Am I missing something here?</p>
  
  <p>*EDIT: I apologize for how unclear I was with that initially. Basically, <code>@startDate</code> should be set to 01-01-XXXX, where XXXX is whatever year today's date is a part of. It's being compared against another <code>DATETIME</code> variable. I hope that clarifies things.</p>