• The error is what is says. The CTE needs a semi colon before it runs.

    If you have a CTE using the WITH statement, you can't have this.

    select col1 from mytable

    with mycte(xx, yy) ...

    you need this:

    select col1 from mytable

    ;

    with mycte(xx, yy) ...

    Find the line from the error, and add a semi colon.l