Home Forums SQL Server 2008 T-SQL (SS2K8) GetDate() 5 Years ago without time formated 'YYYY-MM-DD' RE: GetDate() 5 Years ago without time formated 'YYYY-MM-DD'

  • Welsh Corgi (6/24/2013)


    Thanks for the help guys.

    I'm using the Data calculation in the WHERE Clause.

    WHERE Effective_Date < CONVERT(DATE, DateAdd(yy, - 5, GetDate()));

    Does it matter which method I use as far as performance?

    You do need to cast the calculated value as exactly the same data type as the table column. Otherwise, SQL might be forced to do an implicit conversion on the table column, which could cause a huge performance hit. (Btw, this applies to other data types as well, not just datetime-related types.)

    In this case, you seem to be doing that already, so you should be OK.

    I've not had any issues with a GETDATE() constant vs a variable either, but that could easily happen if the data type of the variable was different from the result of a calculation.

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