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.

Error Message:
Msg 319, Level 15, State 1, Line 3
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.

Severity level:
15.

Description:
This error message appears when you try to use a common table expression or an xmlnamespace clause, but the previous statement has not been terminated by a semicolon.

Consequences:
The SQL statement cannot be parsed and further execution is stopped.

Resolution:
Error of the Severity level 16 are generated by the user and can be fixed by the SQL Server user. The statement can not be run this way. You either must terminate the previous statement with a semicolon or begin the common table expression with a semicolon.

Versions:
This error message was introduced with SQL Server 2005.

Example(s):
SELECT * FROM (SELECT 1 UNION ALL SELECT 2) x (c1)

WITH myCte
AS
(SELECT 1)

SELECT * FROM myCte

Remarks:
In the above example we try to use the common table expression myCte. Because the previous statement has not been terminated with a semicolon, the error is raised.

It is considered best practise to terminate all statements with a semicolon.




Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |