Can we use NEWID(), or RAND() in function?

 Posted by Virendradugar on 9/10/2009 | Category: Sql Server Interview questions | Views: 7975
Answer:

No


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Pandians on: 9/10/2009
Hi Virendradugar

Your question is :
Can we use nondeterministic functions such as GETDATE(), NEWID(), or RAND() in function?

Generally....

GETDATE() /GETUTCDATE() / CURRENT_TIMESTAMP are Non-Deterministic function. But we can use it in User Defined Function.

NEWID() and RAND() can not be used.

CREATE FUNCTION Ufn_Test() RETURNS DATETIME
BEGIN
DECLARE @A DATETIME
SELECT @A = GETDATE()
RETURN(@A)
END

SELECT dbo.Ufn_Test()

Cheers

Login to post response