The first error message is giving you the solution to the problem.
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.
This is a common table expression and it's a powerful tool that will help you in many scenarios. You can read more about them here[/url] and here. But feel free to explore for more information on the subject. And don't forget to ask any other specific questions you have.:-)
EDIT: I forgot to mention that you must terminate your previous statement with a semicolon (;) and even try to terminate all of your statements with it to avoid future problems.