This question already has an answer here:

I have discovered that when I run a CTE in a query window it must have the leading ; but if I am going to run a CTE in a stored procedure it does not need the ;

To me, it would be needed in both places or neither place. Why is this punctuation need in one area and not the other?

marked as duplicate by Max Vernon, Community Feb 15 '17 at 16:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


It's not that a CTE needs a leading ;, but that the statement before must end with a ;.

If the statement with the CTE is the first statement in a batch (or the first statement in your SP), then there's no statement before it to end with a ;

There's a StackOverflow question about it with more detail.

Not the answer you're looking for? Browse other questions tagged or ask your own question.