I have a procedure returning the datetime of a particular timeZone .
CREATE Function [dbo].GetMyDate()
Returns DATETIME
As
Begin
Return DateAdd(Hour,1,GetUTCDATE())
End
If I call it two or three times in ONE T-SQL statement, will it give me the exactly same timestamp??
Or will it return different timestamps??
For eg,
SELECT 1 FROM TABLE_A WHERE GetMyDate() between GetMyDate() AND GetMyDate()
If I execute the above statement, will it always give “1” ??
Can you post it as an answer…
In short, no, it will not.
The function in your testscenario gets executed three times.Now considering SQL Server’s
DateTimedatatype ony being accurate to Rounded increments of .000, .003, or .007 seconds, you can get different results between calls. The only reason you don’t see them in your testscenario is because all calls return within the same time interval.Proof of concept
Following script might take a while to execute but it will stop when the three seperate calls don’t occur within the same interval.