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
I’m getting an error:
Incorrect syntax near the keyword
'with'. If this statement is a
common table expression, an xmlnamespaces clause or a change tracking
context clause, the previous statement must be terminated with a
semicolon.
Can any one solve this issue?
Terminate the previous statement with a semicolon
For consistency and clarity, it doesn’t hurt to terminate all statements with a semicolon.