Someone asked me today if I knew that you couldn't use GETDATE() in functions in SQL Server. Well, I did, so I dug out this solution I had found a while back, and decided to post it, since I am sure others have come across the same issue.
Basically, you use a view to do the work for you... here you go!
CREATE VIEW Function_Assist_GETDATE
/********************************************************** A view to return one row, with one column, the current * date/time from the built-in function GETDATE(). This * view allows a UDF to bypass the restriction on access to * the non-deterministic getdate() function.** Attribution: Based on a newsgroup posting in by Mikhail * Berlyant in microsoft.public.sqlserver.programming * * Common Usage:DECLARE @dtVar datetimeselect @dtVAr = [GetDate] from Function_Assist_GETDATE**********************************************************/
AS SELECT getdate() as [GetDate]
GO
GRANT SELECT on Function_Assist_GETDATE to PUBLICGO
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, © Copyright 2010
E-mail