Will GETUTCDATE() return the same value if used twice in the same statement?

Thanks to the links provided by gbn, I believe this answers my question:

In common with rand() It is evaluated once per column but once evaluated remains the same for all rows.

look at the ComputeScalar operator properties in the actual execution plan you will see that GetDate() is evaluated twice.

I checked, and it appears that this still happens the same way in SQL Server 2008: GetUtcDate() is evaluated twice in the execution plan. It is not going to produce different results per row, but it is possible that it could produce a different result per column if the timing ended up just right.

Edit

I can actually prove this behavior! Try this:

select GETUTCDATE(), RAND(), RAND(), ...[~3000 RAND()s]..., RAND(), GETUTCDATE()
from [TableOfYourChoice]

In my experiment, I ended up with 2011-05-17 20:47:34.247 in the first column and 2011-05-17 20:47:34.250 in the final column, showing a difference of three milliseconds as a result of the evaluation of all the RAND()s between the first and second calls to GETUTCDATE().

Leave a Comment