开发者

SQL Function without input parameters

How to create a SQL Function without input parameters

Im geting a error for following code

create function function_name 
RETURN datetime AS 
BEGIN 
DECLARE @var datetime
SELECT  @var=CURRENT_TIMESTAMP 
RETURN @var
END

Error

开发者_如何转开发> 
> Msg 156, Level 15, State 1, Procedure
> fx_getcurrent_date, Line 2 Incorrect
> syntax near the keyword 'RETURN'. Msg
> 178, Level 15, State 1, Procedure
> fx_getcurrent_date, Line 7 A RETURN
> statement with a return value cannot
> be used in this context.


You are missing your ()'s. Also, it should be RETURNS for the first RETURN.

CREATE FUNCTION function_name
(
) 
RETURNS DATETIME 
AS 
BEGIN 
    DECLARE @var datetime 
    SELECT @var=CURRENT_TIMESTAMP 
    RETURN @var 
END


When you create a function, the return type should be declared with RETURNS, not RETURN.


Its the () you are missing after function name and also use RETURNS after function name.

Refer this link - http://msdn.microsoft.com/en-us/library/ms186755.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜