• Good question! Thank you Ron.

    About 2 years ago I read the BOL reference article on common table expressions and since that time I clearly remember that it stated in the remarks section that "When a CTE is used in a statement that is part of a batch, the statement before it must be followed by a semicolon". Since that time I got into habit of always starting the cte expression with a semicolon, i.e.

    ;with records (some_columns) as

    (

    select ...

    )

    Because of that reference I answered today's question incorrectly figuring that surely the statement like this:

    create view view_name as

    ;with records (some_columns) as

    (

    select ...

    ) -- etc

    will never fly due to that semicolon. This taught me a lesson to read the BOL remarks more carefully. The one about semicolon talks about the batch but if the view definition has only one statement in it then no semicolon is required before the cte.

    Oleg