Im using SQL Server 2005 . I have 2 WITH Clauses in my stored procedure
WITH SomeClause1 AS
(
SELECT ....
)
WITH SomeClause2 AS
(
SELECT ....
)
But the error occurs
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
What are my options? Is there any splitter I don't know about?
Mladen Prajdic suggested this as a solution for "with xmlnamespaces", works great.
http://itknowledgeexchange.techtarget.com/sql-server/using-xmlnamespaces-within-a-function/
Forget about adding a ";" to the previous statement, like the error message says. Just get in the habit of always coding it like: ";WITH" and you'll be fine...
however, you must connect multiple CTEs with commas, but the ";WITH" always has a semicolon before it:
Use a comma to separate CTEs
Doesn't work for me.
In my case I'm using the CTE value within the RETURN clause of a table-valued user-defined function. If I wrap the RETURN clause in BEGIN-END I get the same error message, but a bare RETURN() clause works okay. I believe the error message is incorrect in this case.
This works: