0
Create FUNCTION [dbo].[GetAllChildSpaces] 
(
    @CustomSpaceId varchar(40),
    @Userid int 
)
RETURNS NVARCHAR(MAX)
AS
BEGIN   
    DECLARE @Totalspace NVARCHAR(MAX)
    DECLARE  @tblTotalSpace table (CustomSpaceId NVARCHAR(40))

    WITH Hierachy (CustomSpaceId) AS 
     ( 
     SELECT  CustomSpaceId FROM  CV_CustomSpace e 
     UNION ALL 
     SELECT  e1.CustomSpaceId FROM  CV_CustomSpace e1 INNER JOIN Hierachy p  ON e1.ParentID = p.CustomSpaceId 
     ) 

  INSERT INTO @tblTotalSpace (CustomSpaceId)

  SET @Totalspace=( 
      SELECT STUFF((SELECT ',' + CAST(CustomSpaceId as varchar(50)) 
      FROM @tblTotalSpace FOR XML PATH('')) ,1,1,'') AS TotalSpaceID
  )

  DROP TABLE @tblTotalSpace

  return @Totalspace  
 END 

エラーが発生しました:

キーワードの近くの構文が正しくありません'with'。このステートメントが共通テーブル式、xmlnamespaces節、または変更追跡コンテキスト節である場合、前のステートメントはセミコロンで終了する必要があります。

誰かがこの問題を解決できますか?

4

2 に答える 2

1

Terminate the previous statement with a semicolon

Create FUNCTION [dbo].[GetAllChildSpaces] ( @CustomSpaceId varchar(40), @Userid int ) RETURNS NVARCHAR(MAX) AS BEGIN
DECLARE @Totalspace NVARCHAR(MAX) 
DECLARE @tblTotalSpace table (CustomSpaceId NVARCHAR(40)); -- Here

WITH Hierachy (CustomSpaceId) AS 
...

For consistency and clarity, it doesn't hurt to terminate all statements with a semicolon.

于 2012-08-13T11:46:48.117 に答える
1

WITH の前にセミコロンを置く

;with  Hierachy (CustomSpaceId) AS 
 ( .............
于 2012-08-13T11:47:11.773 に答える