title: SQL Efficiency - Query using dateAdd Function twice; or SubQuery and DateAdd Function once; on Date BETWEEN
body: <p>The expense is using the DateAdd function not only in the SELECT, but also in the WHERE; 
  Or using the Sub Query which initially returns more data than I need, but then can be filtered without using the DateAdd function again on the database.</p>
  
  <p>Execution Plan seems to imply that they are identical as far as it is concerned.
  I'm wondering which would be more efficient?</p>
  
  <pre><code>    DECLARE @DateFrom DateTime
      SET @DateFrom = '2011-05-27'
      DECLARE @DateTo DateTime
      SET @DateTo = '2011-06-27'
  
      SELECT id, name, 
      dateAdd(hour, datediff(hour, getdate(), getutcdate()), --UTC offset
              dateadd(second, itsm_requiredbyx, '1/1/1970 12:00 AM')) as itsm_requiredbyx
      FROM tablename
      WHERE dateAdd(hour, datediff(hour, getdate(), getutcdate()), --UTC offset
              dateadd(second, itsm_requiredbyx, '1/1/1970 12:00 AM'))
              BETWEEN @DateFrom AND @DateTo
  
      ORDER BY itsm_requiredbyx desc
  
      ---------------------------------------------------------------------------------------------
  
      SELECT *
      FROM
          (
          select id, name, 
          dateAdd(hour, datediff(hour, getdate(), getutcdate()), --UTC offset
                  dateadd(second, itsm_requiredbyx, '1/1/1970 12:00 AM')) as itsm_requiredbyx
          from tablename 
          ) RR
      WHERE itsm_requiredbyx BETWEEN @DateFrom AND @DateTo
      ORDER BY itsm_requiredbyx desc
  </code></pre>