1

此功能适用于我朋友的 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
4

1 回答 1

1

我想通了,它应该是结果而不是结果,但那是有线的,因为它在我的朋友 sql server 上工作,我不知道如何。

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 Results R ON C.parentID = R.ID
)
INSERT INTO @Result
SELECT ID
FROM Results

RETURN

END
GO
于 2013-02-26T21:10:52.347 回答