January 26, 2011 at 12:54 pm
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)
January 26, 2011 at 1:39 pm
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.
January 26, 2011 at 1:56 pm
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.January 27, 2011 at 2:31 am
Hi siamak.s16
Have you got the solution..?
Interested to know..how it worked..
January 28, 2011 at 10:31 am
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.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply