我有一個SQL函數,我想返回一個表格,但出現錯誤: A RETURN statement with a return value cannot be used in this context
。如何在sql函數中返回表格
這裏是我的查詢:
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 [email protected] -- 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
和錯誤是:
A RETURN statement with a return value cannot be used in this context
你能後,你得到的錯誤之前?它將幫助我們更快地識別問題。 –
帶有返回值的RETURN語句不能在此上下文中使用。 – Cronaldo