Multiple GetDate()

  • Will Multiple GETDATE()s in a single Insert clause have an impact on the performance of a proc?

    There is a proc where GETDATE() is being used in 3 different places.

    INSERT INTO (col1, col2, col3, col4, col5)

    VALUES (4124, GETDATE(), 323, GETDATE(), GETDATE())

    Will the above be that much different than

    DECLARE @DATE DATETIME = GETDATE()

    INSERT INTO (col1, col2, col3, col4, col5)

    VALUES (4124, @DATE, 323, @DATE, @DATE)

  • See this thread. http://sqlblog.com/blogs/andrew_kelly/archive/2008/02/27/when-getdate-is-not-a-constant.aspx

    You may get different results by referencing getdate() multiple times.

  • I'll run a single select getdate() populating a local variable then use that local variable during insert. Less overhead and you will ensure value is the same in all affected columns.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Hi siamak.s16

    Have you got the solution..?

    Interested to know..how it worked..

  • I agree with Paul, it is more consistent and efficient.

    When dealing with time, look at the fact that sql does not have a clock in it, it needs to ask the OS for the time. Generally speaking, the OS needs to ask the (hardware) system clock for it.

    I do this regardless of what language I am in, be it TSql, VBScript, Javascript, or AspNet.

    Director of Transmogrification Services

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply