USE [db]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Get_PageTree]
(@parentId int)
AS
BEGIN
CREATE TABLE [dbo].[#T_Prime_Page](
[PageId] [int] NULL,
[Flag] [bit] NULL,
[ParentId] [int] NULL,
[RootId] [int] NULL,
[PageName] [nvarchar](1550) NULL,
[PageTitle] [nvarchar](1550) NULL,
[Live] [bit] NULL,
[FileName] [nvarchar](1550) NULL,
[UseLink] [bit] NULL,
[Link] [nvarchar](1500) NULL,
[Keywords] [ntext] NULL,
[Description] [ntext] NULL,
[PageBody] [ntext] NULL,
[DisplayOrder] [int] NULL,
[metaTitle] [varchar](1500) NULL,
[metaDesc] [varchar](5000) NULL)
Insert Into #T_Prime_Page
Select * From Prime_Page Where Live = 0
Update #T_Prime_Page Set ParentID = null Where Flag = 0
WITH Page_CTE AS (
SELECT PageID, PageName, PageTitle, FileName, UseLink, Link, Description, ParentId, DisplayOrder, 0 AS Level
FROM #T_Prime_Page
WHERE ParentId is null and PageId = @parentId
UNION ALL
SELECT p.PageID, p.PageName, p.PageTitle, p.FileName, p.UseLink, p.Link, p.Description, p.ParentId, p.DisplayOrder, Level + 1
FROM #T_Prime_Page p
INNER JOIN Page_CTE pcte ON pcte.PageId = p.ParentId
)
SELECT * into #t_Page_CTE
FROM Page_CTE Where PageID <> @parentId Order by Level, DisplayOrder
SELECT *
FROM #t_Page_CTE Where Level = 1 Order by Level, DisplayOrder
SELECT *
FROM #t_Page_CTE Where Level = 2 Order by Level, DisplayOrder
End
GO
您好,我收到错误消息:Msg 319,Level 15,State 1,Procedure Get_PageTree,Line 30 关键字“with”附近的语法不正确。如果此语句是公用表表达式、xmlnamespaces 子句或更改跟踪上下文子句,则前面的语句必须以分号结束。
请帮助创建程序。在此先感谢。