Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot declare variables?

Status
Not open for further replies.

Luzian

Programmer
Nov 27, 2005
103
US
errors:
In Microsoft SQL Server Management Studio Express:
Msg 102, Level 15, State 1, Procedure fn_GetMessages, Line 2
Incorrect syntax near 'RETURNS'.
Msg 178, Level 15, State 1, Procedure fn_GetMessages, Line 6
A RETURN statement with a return value cannot be used in this context.
In visual studio 2005:
Incorrect syntax near the keyword 'DECLARE'.

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

In either case, it seems the "DECLARE" statement causes the error. Removing that line of code proves it.

Here's the minimal query:
Code:
CREATE FUNCTION dbo.fn_GetRoles
RETURNS TABLE
AS
[b][red]DECLARE @some_variable int;[/red][/b]

RETURN
(
	SELECT *
	FROM [Roles]
)
 
Code:
CREATE FUNCTION dbo.fn_GetRoles
RETURNS TABLE
AS
[!]Begin[/!]
DECLARE @some_variable int;

RETURN
(
    SELECT *
    FROM [Roles]
)
[!]End[/!]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
That doesn't work.

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

Incorrect syntax near 'BEGIN'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top