Does GetDate() get re-evaluated for each iteration within loop within a transaction?

I have a scenario where I am looping through a resultset within a transaction and I need to INSERT a unique datetime value within a table for each iteration through the resultset – will GetDate() be recalculated each time or will it only be calculated the first time and then be the same for each iteration through the loop?

My pseudo-code is below:

  • ExecuteNonQuery: Connection property has not been initialized.
  • SQL Server 2014 equivalent to mysql's find_in_set()
  • SQL Server 2008 to SQL Server Compact Edition?
  • SQL Query for Grouping the results based on sequence
  • How to decrease response time of a simple select query?
  • Find records that do not have a corresponding record in the same table
  • BEGIN TRANSACTION
    GO
    
    DECLARE @ID INT 
    DECLARE @table TABLE (/* Columns */) 
    
    WHILE (SELECT COUNT(*) FROM @table WHERE PROCESSED = 0) > 0
          BEGIN
    
                SELECT TOP 1 @ID = ID FROM @table WHERE PROCESSED = 0 
    
                -- INSERT GetDate() into child table at this point. 
                -- Will GetDate() be re-evaluated each time? 
    
                UPDATE @table SET PROCESSED = 1 WHERE ID = @ID 
    
          END
    
    END TRANSACTION
    GO
    

    Thanks in advance!

    One Solution collect form web for “Does GetDate() get re-evaluated for each iteration within loop within a transaction?”

    Yes.

    If you want to avoid re-evaluating it, store its value in a variable before the loop, and insert that instead.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.