troubleshooting Question

what's wrong with this simple function

Avatar of GordonPrince
GordonPrinceFlag for United States of America asked on
Microsoft SQL Server 2005
6 Comments2 Solutions269 ViewsLast Modified:
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?


CREATE FUNCTION [dbo].[DateFromServer] 
RETURNS char(10)
  DECLARE @dat char(10)
  set @dat = (select convert(char(10), getdate(),101))
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros