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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With