我有一个 SQL 函数,我想返回一个表,但我收到一个错误:
A RETURN statement with a return value cannot be used in this context
.
这是我的查询:
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
错误是:
在此上下文中不能使用具有返回值的 RETURN 语句