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

  • 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)

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.