GordonPrince
asked on
what's wrong with this simple function
I'd like a simple, reusable way to select the date (without the time) from the server. I thought I would create a function as shown in the code window.
But the create statement throws these errors:
Msg 102, Level 15, State 1, Procedure DateFromServer, Line 3
Incorrect syntax near 'RETURNS'.
Msg 178, Level 15, State 1, Procedure DateFromServer, Line 8
A RETURN statement with a return value cannot be used in this context.
Any ideas how to fix this simple function coding error? And/or another way to accomplish what I'm trying to accomplish?
But the create statement throws these errors:
Msg 102, Level 15, State 1, Procedure DateFromServer, Line 3
Incorrect syntax near 'RETURNS'.
Msg 178, Level 15, State 1, Procedure DateFromServer, Line 8
A RETURN statement with a return value cannot be used in this context.
Any ideas how to fix this simple function coding error? And/or another way to accomplish what I'm trying to accomplish?
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE FUNCTION [dbo].[DateFromServer]
RETURNS char(10)
AS
BEGIN
DECLARE @dat char(10)
set @dat = (select convert(char(10), getdate(),101))
RETURN(@dat)
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What for you are reinventing the wheel?
GETDATE() returns date from server. You can use CONVERT function to format the result to show only DATE.
Good luck
GETDATE() returns date from server. You can use CONVERT function to format the result to show only DATE.
Good luck
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm just trying to not have to retype the code over and over and hope it comes out the same every time. That's all the function is for.
To be honest is not that much to write to justify a function in this case. Beside that the performance will be negatively impacted by a user define function, even if not by too much.
Open in new window