Home Forums SQL Server 2008 SQL Server 2008 - General Dynamic SQL and DATEADD with User Defined Variable in Number/2nd position RE: Dynamic SQL and DATEADD with User Defined Variable in Number/2nd position

  • ScottPletcher (9/3/2013)


    You don't want to use a function against the END_DATETIME column if you can avoid it, since any function will prevent SQL from using the full seek capabilities against that column in any index(es) in which it might appear.

    I think the code below will do SELECT the same rows as your original query, but adjust the code if/as needed to match you need:

    SELECT *

    FROM dbo.tablename

    WHERE

    END_DATETIME >= DATEADD(HOUR, -@tzoffset, @StartDate) AND

    END_DATETIME <= DATEADD(HOUR, -@tzoffset, @EndDate)

    Same thing I suggested in my post.