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?

| improve this 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.

| improve this answer | | | | |

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