In Microsoft SQL Server Management Studio Express:
In visual studio 2005:
In either case, it seems the "DECLARE" statement causes the error. Removing that line of code proves it. It seems I can't do anything within a function returning a table, but return the table.
Here's the minimal query:
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:
Code:
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. It seems I can't do anything within a function returning a table, but return the table.
Here's the minimal query:
Code:
CREATE FUNCTION dbo.fn_GetRoles
(@parameter int)
RETURNS TABLE
AS
[red]DECLARE @some_variable int;[/red]
RETURN
(
SELECT *
FROM [Roles]
)