# Friday, March 11, 2005

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 datetime
select @dtVAr = [GetDate] from Function_Assist_GETDATE
**********************************************************/

AS
    SELECT getdate() as [GetDate]

GO

GRANT SELECT on Function_Assist_GETDATE to PUBLIC
GO

Friday, March 11, 2005 9:45:00 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, March 09, 2005
Exception handling analyzed...
Wednesday, March 09, 2005 5:47:50 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, March 03, 2005
Tips of the day just aren't...
Thursday, March 03, 2005 11:07:53 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, December 31, 2004
Clearing up the confusion when you need the return value from an insert.
Friday, December 31, 2004 3:25:39 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Thursday, December 30, 2004
Finding all tables where a field exists in SQL Server
Thursday, December 30, 2004 6:09:49 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  | 
# Tuesday, December 28, 2004
How to format a date to a particular format...
Tuesday, December 28, 2004 5:07:14 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, December 27, 2004
How to quickly find out which control caused the postback
Monday, December 27, 2004 10:19:36 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [4]  | 
# Tuesday, December 21, 2004
How to step through your client side code
Tuesday, December 21, 2004 9:26:19 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  | 
# Monday, December 20, 2004
The vb function in C#
Monday, December 20, 2004 9:13:55 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Saturday, December 18, 2004
Just a tip to remind myself
Saturday, December 18, 2004 9:55:17 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, December 15, 2004
A brief look into the System.Diagnostics namespace...
Wednesday, December 15, 2004 8:15:13 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [4]  | 
# Saturday, December 11, 2004
A costly mistake to forget...
Saturday, December 11, 2004 6:29:51 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Friday, December 10, 2004
Too tired to code, so I will at least post a link or two..
Friday, December 10, 2004 2:30:27 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [3]  | 
# Wednesday, December 08, 2004
How to cast to a specific type if you have the string value of the type
Wednesday, December 08, 2004 2:49:20 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [3]  | 
# Monday, December 06, 2004
Quick fix for a "catastrophic" problem!
Monday, December 06, 2004 4:44:29 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |