According to MS docs DATEADD
is a deterministic function hence my function below should be deterministic too:
CREATE FUNCTION [dbo].[Epoch2Date] (@i INT)
RETURNS DATETIME WITH SCHEMABINDING
BEGIN
RETURN DATEADD(SECOND,@i,'1970-01-01 00:00:00')
END
But when I check it with SELECT OBJECTPROPERTY(OBJECT_ID('[dbo].[Epoch2Date]'), 'IsDeterministic')
it returns 0
(Non-deterministic).
- Why it is non-deterministic?
- How can I make my function deterministic?
There is a similar question but it uses non-deterministic function CAST
which is not the case here.