I am having a SQL function and I want to return a table, but I'm getting an error:
A RETURN statement with a return value cannot be used in this context.
Here is my query:
ALTER FUNCTION [dbo].[Fnc_GetParentCategories]-- 21
(
@catId int
)
Returns table
As
Begin
Declare @Table table(Id int identity(1,1),Category_Id int,ParentId int);
declare @cid int;
WITH x AS (
SELECT a.Category_Id, a.ParentId
FROM t_Category a
WHERE a.Category_Id=@CatId -- enter dead node walking here
UNION ALL
SELECT b.Category_Id, b.ParentId
FROM t_Category b
JOIN x ON x.Category_Id =b.ParentId
)
insert into @Table select * from x;
return @Table
end
And the error is:
A RETURN statement with a return value cannot be used in this context