Home >Database >Mysql Tutorial >How to Fix 'Incorrect Syntax near 'with'' in SQL Server When Using Multiple WITH Clauses?
Resolving "Incorrect Syntax near 'with'" Error with Multiple WITH Clauses in SQL Server
When encountering the error "Incorrect syntax near the keyword 'with'...", developers working with SQL Server 2005 may find themselves perplexed when attempting to utilize multiple WITH clauses within a stored procedure. This error often arises when the previous statement lacks a semicolon termination.
To resolve this issue, employ the following method:
Introduce Commas to Separate CTEs (Common Table Expressions)
Instead of using a semicolon between WITH clauses, implement commas to separate them. The updated syntax appears as follows:
;WITH SomeClause1 AS ( SELECT .... ) , SomeClause2 AS ( SELECT .... )
By implementing this modification, you can effectively separate your WITH clauses while maintaining proper syntax.
The above is the detailed content of How to Fix 'Incorrect Syntax near 'with'' in SQL Server When Using Multiple WITH Clauses?. For more information, please follow other related articles on the PHP Chinese website!