HOY HOY - 3 months ago 27
SQL Question

TSQL Error: A RETURN statement with a return value cannot be used in this context

I am just trying to create a function that returns a select statement, but it gives the error:


A RETURN statement with a return value cannot be used in this context.


This is my code:

CREATE FUNCTION [dbo].[Sample] (@SampleValue int)
RETURNS TABLE
AS
BEGIN
RETURN(
SELECT * FROM View_sls
)


Please let me know the solution

gbn gbn
Answer

Wrong syntax, that's all. You don't need BEGIN when you have an "inline table-valued function"

See CREATE FUNCTION and example B

CREATE FUNCTION [dbo].[Sample] (@SampleValue int)
RETURNS TABLE
AS
RETURN
(
 SELECT * FROM View_sls
);
GO
Comments