1

I have a statement like

INSERT INTO target_table
SELECT columns, GETDATE() 
FROM source_table JOIN other tables... 

Normally it seems like GETDATE() is evaluated once for the whole result set and all rows in target_table have the same date value.

Is this a guarantee, or are there edge cases where GETDATE() could return different values for different rows?

Obviously I could assign GETDATE() to a variable to avoid issues -- my question is whether this is strictly necessary or not.

wrschneider
  • 17,913
  • 16
  • 96
  • 176
  • The answer is given in the comments, http://stackoverflow.com/questions/12078202/when-using-getdate-in-many-places-is-it-better-to-use-a-variable#comment16223903_12078717 – GSerg Mar 08 '17 at 15:32
  • Thanks. The answer is mentioned in the accepted answer, even though my question is worded slightly different. (Better to use vs. MUST use) – wrschneider Mar 08 '17 at 15:34
  • 1
    Unfortunately the answer is wrong. The comment is correct. `getdate` is a runtime constant. It is not evaluated per row, but it is evaluated per appearance in the query. – GSerg Mar 08 '17 at 15:36

0 Answers0