此功能适用于我朋友的 Visual Studio 和 SQL Server 2021,但不适用于我的。
它在以下位置返回错误WITH Result (ID)
:
“结果”附近的语法不正确,应为 AW_CHANGE_TRACKING_CONTEXT、AW_ID、AW_XMLNAMESPACES、QUOTED_ID
任何解决方案..?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[hierarchySelect]
(
@CategoryID int
)
RETURNS @Result TABLE (ID int) AS BEGIN
WITH Result (ID)
AS
(
SELECT ID
FROM Categories
WHERE ID = @CategoryID
UNION ALL
SELECT C.ID FROM Categories C
INNER JOIN Result R ON C.parentID = R.ID
)
INSERT INTO @Result
SELECT ID
FROM Result
RETURN
END
GO