Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have two functions: fn_Without_Param and fn_With_Param

 CREATE FUNCTION [dbo].[fn_Without_Param]
 (
 )
 ...
 INNER JOIN .. ON .. AND SubmitDate = CONVERT( varchar(10), GETUTCDATE(), 101 )

and

/*
     I am requesting it so:
    declare @SubmitDate     datetime
    set @SubmitDate = CONVERT( varchar(10), GETUTCDATE(), 101 )
    select * from [dbo].[fn_With_Param] (@SubmitDate)
*/



CREATE FUNCTION [dbo].[fn_With_Param]
(
    @SubmitDate datetime    
)
...
INNER JOIN .. ON .. AND SubmitDate = @SubmitDate  

In the first case I have nondeterministic (?) function (because of GETUTCDATE) and I have called the second one with the same input parameter (CONVERT( varchar(10), GETUTCDATE(), 101 ) - meens today date without hours, minutes, seconds, millisecond). Is my function nondeterministic one? How to detect this, maybe sql server has some public mark. Why is the second function slower?

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

I'm not sure if there is a flag, but there is a reference available at http://msdn.microsoft.com/en-us/library/ms178091.aspx of which built in functions are deterministic.

GETDATE() and GETUTCDATE() are nondeterministic because if you call them multiple times with the same parameters, which in this case are none, you get different values. In other words, the return value is not determined by input.

As far as why the second is slower than the first, check for implicit conversion between SubmitDate = @SubmitDate. Are they both datetime?

share|improve this answer
    
+1 Bingo! My fault: SubmitDate is varchar(10). Now they spend the same time on execution. –  garik Jan 20 '11 at 14:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.