abatishchev
abatishchev

Reputation: 100248

Is GETDATE() expensive as DateTime.Now is?

I have heard that DateTime.Now is very expensive call (from here)

Is GETDATE() in SQL 2005/2008 expensive? Have I to cache it into a variable if my stored procedure uses it a number of times?

Upvotes: 6

Views: 2200

Answers (1)

gbn
gbn

Reputation: 432210

It's not expensive: it comes straight from the OS.

I'd cache it anyway. It will most likely be different for separate calls if you have multiple statements. Say you have multiple inserts, surely you'd want the value to correlate acrosss tables?

If it's use in a SELECT, say, for output then it's only evaluated once usually.

Upvotes: 6

Related Questions