Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Why no GetDate() in a UDF?

Author  Topic 

Blastrix
Posting Yak Master

208 Posts

Posted - 2003-09-10 : 12:41:08
I realize that GetDate() and quite a few other functions can not be called from inside of a UDF, but does anyone know why? It seems like such a strange limitation that a UDF can't use other system functions.

Thanks,
Steve

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-09-10 : 12:49:12
a UDF must be deterministic, meaning that given the same inputs, it always returns the same output.

The GetDate() function is nondeterministic.


- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-09-10 : 12:54:07
Why not pass Getdate() in as a parameter?



Brett

8-)

SELECT @@POST=NewId()

That's correct! It's an AlphaNumeric!
Go to Top of Page

Shaner
Starting Member

9 Posts

Posted - 2003-09-11 : 10:28:05
You can also set up a view as follows. Then access the date from the view instead. Sort of messy but a good workaround.

----------------------------------------
CREATE VIEW dbo.vwGetUTCDate
AS
SELECT GETUTCDATE() AS CurrentDate
----------------------------------------

----------------------------------------
CREATE FUNCTION [dbo].[fnCalcElapsedTime] (
@TimeIn datetime

RETURNS decimal(15,2) AS
BEGIN

DECLARE @Elapsed decimal(15,2),
@UTC datetime

SELECT @Elapsed = CONVERT(decimal(15,2), ROUND( (CONVERT(decimal(15,2),(DATEDIFF(mi,@TimeIn,CurrentDate)))/60) ,2))
FROM vwGetUTCDate

RETURN @Elapsed
END
----------------------------------------


Go to Top of Page
   

- Advertisement -