5
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 子句或更改跟踪上下文子句,则前面的语句必须以分号结束。

请帮助创建程序。在此先感谢。

4

2 回答 2

16

在 WITH 之前放置一个分号 (;)。

;WITH Page_CTE  AS (

正如错误消息告诉您的那样,前面的语句应该以分号结束。

于 2013-06-20T15:17:03.273 回答
2

WITH并且所有新的 2005 年后命令关键字都需要在它们和任何以前的命令之间使用分号 (";")。因此,只需在它之前的命令之前WITH和之后添加一个。UPDATE

于 2013-06-20T15:16:50.707 回答