Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8436171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:06:40+00:00 2026-06-10T07:06:40+00:00

By better, I mean does it improve performance by some non-marginal amount? That is

  • 0

By better, I mean does it improve performance by some non-marginal amount?

That is to say, each time I call GETDATE(), what amount of work does the server do to return that value?

If I’m using GETDATE() in many places in a stored procedure, should I instead be creating a variable to store the date of the transaction?

declare @transDate datetime = GETDATE()

Bench-marking data would be fantastic.

EDIT I want to clarify: I’m interested mainly in the actual performance differences between these two possibilities, and whether or not it is significant.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:06:42+00:00Added an answer on June 10, 2026 at 7:06 am

    [NOTE: If you are going to downvote this answer, please leave a comment explaining why. It has already been downvoted many times, and finally ypercube (thank you) explained at least one reason why. I can’t remove the answer because it is accepted, so you might as well help to improve it.]

    According to this exchange on Microsoft, GETDATE() switched from being constant within a query to non-deterministic in SQL Server 2005. In retrospect, I don’t think that is accurate. I think it was completely non-deterministic prior to SQL Server 2005 and then hacked into something called “non-deterministic runtime constant” since SQL Server 2005″. The later phrase really seems to mean “constant within a query”.

    (And GETDATE() is defined as unambiguously and proudly non-deterministic, with no qualifiers.)

    Alas, in SQL Server, non-deterministic does not mean that a function is evaluated for every row. SQL Server really does make this needlessly complicated and ambiguous with very little documentation on the subject.

    In practice the function call is evaluated when the query is running rather than once when the query is compiled and its value changes each time it is called. In practice, GETDATE() is only evaluated once for each expression where it is used — at execution time rather than compile time. However, Microsoft puts rand() and getdate() into a special category, called non-deterministic runtime constant functions. By contrast, Postgres doesn’t jump through such hoops, it just calls functions that have a constant value when executed as “stable”.

    Despite Martin Smith’s comment, SQL Server documentation is simply not explicit on this matter — GETDATE() is described as both “nondeterministic” and “non-deterministic runtime constant”, but that term isn’t really explained. The one place I have found the term , for instance, the very next lines in the documentation say not to use nondeterministic functions in subqueries. That would be silly advice for “nondeterministic runtime constant”.

    I would suggest using a variable with a constant even within a query, so you have a consistent value. This also makes the intention quite clear:
    You want a single value inside the query. Within a single query, you can do something like:

    select . . . 
    from (select getdate() as now) params cross join
         . . . 
    

    Actually, this is a suggestion that should evaluate only once in the query, but there might be exceptions. Confusion arises because getdate() returns the same value on all different rows — but it can return different values in different columns. Each expression with getdate() is evaluated independently.
    This is obvious if you run:

    select rand(), rand()
    from (values (1), (2), (3)) v(x);
    

    Within a stored procedure, you would want to have a single value in a variable. What happens if the stored procedure is run as midnight passes by, and the date changes? What impact does that have on the results?

    As for performance, my guess is that the date/time lookup is minimal and for a query occurs once per expression as the query starts to run. This should not really a performance issue, but more of a code-consistency issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A SorteDictionary is according to MSDN sorted on the key. Does that mean that
What does it mean and how it can be removed (reformatted for better readability)?
Does it mean ASC is better for queries such as PRICE > 40 and
Is there a better method (using Windows) for getting a moderate amount of data
I’m looking at ways to improve the consistency, brevity, and readability of some code
Someone said to me that JSF is better at sharing information within the context,
I am having a performance problem with JavaDB (Derby) writing transactions. Each transaction takes
Recently I heard Kirk Pepperdine speak about changing garbage collectors for better performance --
We have several latency-sensitive pipeline-style programs that have a measurable performance degredation when run
I've been recently asked to learn some MATLAB basics for a class. What does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.